# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
630868 | kyaruru | Schools (IZhO13_school) | Java | 1845 ms | 27668 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.io.*;
import java.util.*;
public class school {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
PriorityQueue<int[]> aa=new PriorityQueue<>((o1, o2) -> o1[0]-o2[0]);
PriorityQueue<int[]> bb=new PriorityQueue<>((o1, o2) -> o1[1]-o2[1]);
String[] s=bf.readLine().split(" ");
int a=Integer.parseInt(s[0]),p=Integer.parseInt(s[1]),q=Integer.parseInt(s[2]);
int[][] k=new int[a][2];
for(int i=0; i<a; i++){
s=bf.readLine().split(" ");
int x=Integer.parseInt(s[0]),y=Integer.parseInt(s[1]);
k[i][0]=x; k[i][1]=y;
}
Arrays.sort(k,(o1, o2) -> (o2[0]-o2[1])-(o1[0]-o1[1]));
int i=0;
for(; i<p; i++) aa.add(k[i]);
for(; i<p+q; i++) bb.add(k[i]);
for(; i<a; i++){
if(!bb.isEmpty()) {
if (bb.peek()[1] < k[i][1]) {
int[] r = bb.poll();
if (!aa.isEmpty() && r[0] > aa.peek()[0]) {
aa.poll();
aa.add(r);
}
bb.add(k[i]);
}
}
else if(!aa.isEmpty()){
if(aa.peek()[0]<=k[i][0]){
aa.poll();
aa.add(k[i]);
}
}
}
long sum=0;
while(!aa.isEmpty()) sum+=aa.poll()[0];
while(!bb.isEmpty()) sum+=bb.poll()[1];
System.out.println(sum);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |