File Annotation
Not logged in
23dfcca431 2011-02-23        kinaba: import java.io.*;
23dfcca431 2011-02-23        kinaba: import java.util.*;
23dfcca431 2011-02-23        kinaba: 
23dfcca431 2011-02-23        kinaba: public class <CLASSNAME>
23dfcca431 2011-02-23        kinaba: {
23dfcca431 2011-02-23        kinaba: 	public static void main(String[] arg)
23dfcca431 2011-02-23        kinaba: 	{
23dfcca431 2011-02-23        kinaba: 		Scanner sc = new Scanner(System.in);
23dfcca431 2011-02-23        kinaba: 		int T = sc.nextInt();
23dfcca431 2011-02-23        kinaba: 		for(int C=1; C<=T; ++C)
23dfcca431 2011-02-23        kinaba: 		{
23dfcca431 2011-02-23        kinaba: 			System.out.printf("Case #%d: ", C);
23dfcca431 2011-02-23        kinaba: 			(new <CLASSNAME>(sc)).caseMain();
23dfcca431 2011-02-23        kinaba: 		}
23dfcca431 2011-02-23        kinaba: 	}
23dfcca431 2011-02-23        kinaba: 
23dfcca431 2011-02-23        kinaba: 	Scanner sc;
23dfcca431 2011-02-23        kinaba: 	<CLASSNAME>( Scanner sc ) { this.sc = sc; }
23dfcca431 2011-02-23        kinaba: 
23dfcca431 2011-02-23        kinaba: 	void caseMain()
23dfcca431 2011-02-23        kinaba: 	{
23dfcca431 2011-02-23        kinaba: 		int n = sc.nextInt();
23dfcca431 2011-02-23        kinaba: 		long[] x = new long[n];
23dfcca431 2011-02-23        kinaba: 		for(int i=0; i<n; ++i) x[i] = sc.nextInt();
23dfcca431 2011-02-23        kinaba: 		long[] y = new long[n];
23dfcca431 2011-02-23        kinaba: 		for(int i=0; i<n; ++i) y[i] = sc.nextInt();
23dfcca431 2011-02-23        kinaba: 
23dfcca431 2011-02-23        kinaba: 		System.out.println(solve(x, y, n));
23dfcca431 2011-02-23        kinaba: 	}
23dfcca431 2011-02-23        kinaba: 
23dfcca431 2011-02-23        kinaba: 	long solve(long[] x, long[] y, int n)
23dfcca431 2011-02-23        kinaba: 	{
23dfcca431 2011-02-23        kinaba: 		Arrays.sort(x);
23dfcca431 2011-02-23        kinaba: 		Arrays.sort(y);
23dfcca431 2011-02-23        kinaba: 		long s = 0;
23dfcca431 2011-02-23        kinaba: 		for(int i=0; i<n; ++i)
23dfcca431 2011-02-23        kinaba: 			s += x[i] * y[n-1-i];
23dfcca431 2011-02-23        kinaba: 		return s;
23dfcca431 2011-02-23        kinaba: 	}
23dfcca431 2011-02-23        kinaba: }