?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
120965699 |
Practice: amireripmav786 |
1519C - 28 | Java 11 | Time limit exceeded on test 5 | 2000 ms | 5032 KB | 2021-06-30 19:08:56 | 2021-06-30 19:08:56 |
import java.util.*; import java.lang.*; import java.io.*; import java.math.*; public class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); StringBuilder fo = new StringBuilder(); int test=sc.nextInt(); while(test-->0) { int n = sc.nextInt(); Map<Long, List<Long>> map = new HashMap<>(); long a[] = new long[n]; for(int i=0;i<n;i++) { a[i] = sc.nextLong(); map.putIfAbsent(a[i], new ArrayList<>()); } for(int i=0;i<n;i++) { map.get(a[i]).add(sc.nextLong()); } long ans[] =new long[n]; for(List<Long> value : map.values()){ Collections.sort(value, Collections.reverseOrder()); for(int i=1;i<value.size();i++) { value.set(i,value.get(i-1)+value.get(i)); } } for(List<Long> i : map.values()) { for(int j=0;j<n;j++) { int index = (i.size()/(j+1))*(j+1)-1; if(index!=-1) ans[j] = ans[j] + i.get(index); } } for(int i=0;i<ans.length;i++) fo.append(ans[i]+" "); fo.append("\n"); } System.out.println(fo); } }
?
?
?
?