Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class MinimumScalarProduct {
- public MinimumScalarProduct() {
- }
- public static void main(String[] args)
- {
- Scanner sc = new Scanner(System.in);
- int t,n,ctr=0,i,j;
- long ans=0;
- t = sc.nextInt();
- for (i=1;i<=t;i++) //number of test cases
- {
- ans = 0;
- n = sc.nextInt();
- int nArray1[] = new int[n];
- int nArray2[] = new int[n];
- for (j=0;j<n;j++) //initialize array1
- {
- nArray1[j] = sc.nextInt();
- }
- for (j=0;j<n;j++) //initialize array2
- {
- nArray2[j] = sc.nextInt();
- }
- Arrays.sort(nArray1); //sort
- Arrays.sort(nArray2); //sort
- ctr = nArray2.length-1; //get last index of array2
- for (j=0;j<n;j++)
- {
- ans += (long)(nArray1[j] * nArray2[ctr]);
- ctr--;
- }
- System.out.println("Case #" + i + ": " + ans);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement