Thursday, 8 May 2014

SPOJ Problem Set (classical) 1025. Fashion Shows Problem code: FASHION

//http://www.spoj.com/problems/FASHION/

#include<stdio.h>
#include<algorithm>    //for using sort function
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int i,ppl;
        scanf("%d",&ppl);
        int men[ppl],women[ppl];
        for(i=0;i<ppl;i++)
            scanf("%d",&men[i]);
        for(i=0;i<ppl;i++)
            scanf("%d",&women[i]);
        sort(men,men+ppl);  //sorts array 'men' from zeroth to ppl-1 th index
        sort(women,women+ppl);
        long long ans=0;
        for(i=0;i<ppl;i++)
            ans+=men[i]*women[i]; //hotness maximised
        printf("%d\n",ans);
    }
    return 0;
}

No comments:

Post a Comment