| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 630612 | kyaruru | Schools (IZhO13_school) | Java | 2080 ms | 51488 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) -> o2[0]-o1[0]);
        PriorityQueue<int[]> bb=new PriorityQueue<>((o1, o2) -> o2[1]-o1[1]);
        String[] s=bf.readLine().split(" ");
        int a=Integer.parseInt(s[0]),p=Integer.parseInt(s[1]),q=Integer.parseInt(s[2]);
        boolean[] use=new boolean[a];
        for(int i=0; i<a; i++){
            s=bf.readLine().split(" ");
            int x=Integer.parseInt(s[0]),y=Integer.parseInt(s[1]);
            aa.add(new int[]{x,y,i});
            bb.add(new int[]{x,y,i});
        }
        int[][] ka=new int[p+q][2];
        int i=0,tp=p,tq=q;
        while(i<p+q){
            while(use[aa.peek()[2]]) aa.poll();
            while(use[bb.peek()[2]]) bb.poll();
            int[] r;
            if(tq==0 || aa.peek()[0]>bb.peek()[1]) {
                r = aa.poll();
                ka[i][0]=r[0];
                ka[i][1]=r[1];
                use[r[2]]=true;
                tp--;
            }
            else if(tp==0 || aa.peek()[0]<=bb.peek()[1]){
                r = bb.poll();
                ka[i][0]=r[0];
                ka[i][1]=r[1];
                use[r[2]]=true;
                tq--;
            }
            i++;
        }
        Arrays.sort(ka,(o1, o2) -> (o2[0]-o2[1])-(o1[0]-o1[1]));
        i=0;
        long sum=0;
        for(; i<p; i++) sum+=ka[i][0];
        for(; i<p+q; i++) sum+=ka[i][1];
        System.out.println(sum);
    }
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
