CodeJam 2008 Minimum Scale Product

coding cpp codejam algo

This problem was pretty simple once you figure out how it was supposed to be done. The phrasing of the question was somewhat problematic and it took me a few moments before I am able to figure out the solution. The solution was pretty simple, but it could be even easily computed in Python. Anyway, the result is that I have passed the small input, but for the large input, it was marked incorrect. So…

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <map>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
using namespace std;

#define FOR(i, n) for(int i=0; i<n; i++)

int main(){
    int TC; scanf("%d", &TC);
    FOR(tc, TC){
        int n; scanf("%d", &n);
        double v[2][n];
        
        FOR(j, 2){
            FOR(i, n){ scanf("%d", &v[j][i]); }
        }
        
        sort(v[0], v[0]+n);
        sort(v[1], v[1]+n);
        
        double t = 0;
        FOR(i, n){
            t += v[0][i] * v[1][n-1-i];
        }
        
        printf("Case #%d: %d\n", tc+1, t);
    }
    
    return 0;
}