-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaverageseasy.java
67 lines (44 loc) · 1.12 KB
/
averageseasy.java
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class averageseasy
{
public static double avg(ArrayList<Integer> list)
{
double sum = 0;
for(int a : list)
sum += a;
return sum / (double)(list.size());
}
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int cases = scan.nextInt();
scan.nextLine();
scan.nextLine();
while( cases --> 0 )
{
int counter = 0;
int c = scan.nextInt();
int e = scan.nextInt();
ArrayList<Integer> cs = new ArrayList<>(c);
ArrayList<Integer> ec = new ArrayList<>(e);
while(c -- > 0)
cs.add(scan.nextInt());
while(e -- > 0)
ec.add(scan.nextInt());
Collections.sort(cs);
for(int i=cs.size()-1; i >= 0; i--)
{
double csavg = avg(cs);
double ecavg = avg(ec);
ec.add(0, cs.remove(i));
if(avg(cs) > csavg && avg(ec) > ecavg)
counter++;
cs.add(i,ec.remove(0));
}
System.out.println(counter);
}
scan.close();
}
}