-
Notifications
You must be signed in to change notification settings - Fork 0
/
BerlandRegional1519C.java
66 lines (61 loc) · 1.89 KB
/
BerlandRegional1519C.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
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
public class BerlandRegional1519C {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int [] u = new int [200001];
int [] s = new int [200001];
int t = sc.nextInt();
for (int i = 0; i < t; ++i) {
HashMap <Integer, ArrayList<BigInteger>> hmap= new HashMap <Integer, ArrayList<BigInteger>> ();
int n = sc.nextInt();
for (int j = 0; j < n; ++j) {
u[j] = sc.nextInt();
}
for (int j = 0; j < n; ++j) {
s[j] = sc.nextInt();
}
for (int j = 0; j < n; ++j) {
if (hmap.containsKey(u[j])) {
ArrayList <BigInteger> arr = hmap.get(u[j]);
arr.add(BigInteger.valueOf(s[j]));
hmap.put(u[j], arr);
}
else {
ArrayList <BigInteger> arr = new ArrayList<BigInteger> ();
arr.add(BigInteger.valueOf(s[j]));
hmap.put(u[j], arr);
}
}
for (int j : hmap.keySet()) {
Collections.sort(hmap.get(j), Collections.reverseOrder());
ArrayList <BigInteger> arr = hmap.get(j);
for (int k = 1; k < arr.size(); ++k) {
arr.set(k, arr.get(k).add(arr.get(k-1)));
}
hmap.put(j, arr);
}
BigInteger prev = new BigInteger("999");
for (int j = 1; j <= n; ++j) {
BigInteger tot = new BigInteger("0");
if (prev.equals(BigInteger.ZERO)) {
System.out.print("0 ");
continue;
}
for (int k : hmap.keySet()) {
ArrayList <BigInteger> arr = hmap.get(k);
int lst = arr.size() - (arr.size()%j) - 1;
BigInteger item = lst<0?BigInteger.ZERO:arr.get(lst);
tot = tot.add(item);
}
prev = tot;
System.out.print(tot + " ");
}
System.out.println();
}
sc.close();
}
}