Pages

Friday, 30 January 2015

Solution Of Candy Distribution Spoj CADYDIST

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{  long long int  n,i,j,s;
  while(1)
 { s=0;
scanf("%lld",&n);
 if(n==0)
 break;
  long long int a[n],b[n];
  for(i=0;i<n;i++)
    scanf("%lld",&a[i]);
    for(i=0;i<n;i++)
      scanf("%lld",&b[i]);
      sort(a,a+n);
      sort(b,b+n);
    for(i=0,j=n-1;i<n,j>=0;i++,j--)
      s=s+a[i]*b[j];
      printf("%lld\n",s);
    }
    return 0;
    }













1 comment: