-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJanuary LongChallenge(3)
More file actions
50 lines (48 loc) · 1.36 KB
/
January LongChallenge(3)
File metadata and controls
50 lines (48 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.company;
import java.util.Arrays;
import java.util.Scanner;
public class jan32 {
public static void main(String[] args)throws java.lang.Exception {
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
while(n--!=0){
int size1=scan.nextInt();
int size2=scan.nextInt();
int[] arr1=new int[size1];
int[] arr2=new int[size2];
int sum1=0,sum2=0;
for(int i=0;i<size1;i++){
arr1[i]=scan.nextInt();
sum1+=arr1[i];
}
for(int i=0;i<size2;i++){
arr2[i]=scan.nextInt();
sum2+=arr2[i];
}
if(sum1>sum2){
System.out.println(0);
continue;
}
Arrays.sort(arr1);
Arrays.sort(arr2);
int count=0;
int j=size2-1;
for(int i=0;i<size1;i++){
sum1=sum1-arr1[i];
sum2=sum2-arr2[j];
sum1=sum1+arr2[j];
sum2=sum2+arr1[i];
count++;
j--;
if(sum1>sum2 || j<0){
break;
}
}
if(sum1>sum2){
System.out.println(count);
}else{
System.out.println(-1);
}
}
}
}