Submission #631095

# Submission time Handle Problem Language Result Execution time Memory
631095 2022-08-17T16:58:50 Z kyaruru Schools (IZhO13_school) Java 11
25 / 100
2000 ms 29200 KB
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[]> m=new PriorityQueue<>((o1, o2) -> (o1[0]-o1[1])-(o2[0]-o2[1]));
        PriorityQueue<int[]> s=new PriorityQueue<>((o1, o2) -> o1[1]-o2[1]);
        String[] sa=bf.readLine().split(" ");
        int a=Integer.parseInt(sa[0]),p=Integer.parseInt(sa[1]),q=Integer.parseInt(sa[2]);
        int[][] k=new int[a][2];
        for(int i=0; i<a; i++){
            sa=bf.readLine().split(" ");
            int x=Integer.parseInt(sa[0]),y=Integer.parseInt(sa[1]);
            k[i][0]=x; k[i][1]=y;
        }
        Arrays.sort(k,(o1, o2) -> o2[0]-o1[0]);
        for(int i=0; i<a; i++){
            if(p==0){
                if(s.size()<q) s.add(k[i]);
                else{
                    if(!s.isEmpty() && s.peek()[1]<k[i][1]){
                        s.poll();
                        s.add(k[i]);
                    }
                }
            }
            else {
                if (m.size() < p) m.add(k[i]);
                else{
                    if(s.size()<q){
                        int[] r=m.poll();
                        if(r[0]-r[1]>=k[i][0]-k[i][1]) {
                            s.add(k[i]);
                            m.add(r);
                        }
                        else {
                            s.add(r);
                            m.add(k[i]);
                        }
                    }
                    else{
                        if(!s.isEmpty() && s.peek()[1]<k[i][1]){
                            s.poll();
                            s.add(k[i]);
                        }
                    }
                }
            }
        }
        long sum=0;
        while(!m.isEmpty()) sum+=m.poll()[0];
        while(!s.isEmpty()) sum+=s.poll()[1];
        System.out.println(sum);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 71 ms 8868 KB Output is correct
2 Correct 67 ms 9024 KB Output is correct
3 Correct 69 ms 8884 KB Output is correct
4 Incorrect 74 ms 8868 KB Output isn't correct
5 Incorrect 76 ms 8812 KB Output isn't correct
6 Incorrect 75 ms 9112 KB Output isn't correct
7 Incorrect 484 ms 14936 KB Output isn't correct
8 Correct 439 ms 14984 KB Output is correct
9 Incorrect 455 ms 15068 KB Output isn't correct
10 Incorrect 439 ms 14900 KB Output isn't correct
11 Incorrect 519 ms 15168 KB Output isn't correct
12 Incorrect 584 ms 14820 KB Output isn't correct
13 Incorrect 1024 ms 17888 KB Output isn't correct
14 Incorrect 1054 ms 20376 KB Output isn't correct
15 Incorrect 1503 ms 23060 KB Output isn't correct
16 Correct 1450 ms 25080 KB Output is correct
17 Incorrect 1804 ms 27036 KB Output isn't correct
18 Execution timed out 2031 ms 27716 KB Time limit exceeded
19 Incorrect 1962 ms 28488 KB Output isn't correct
20 Execution timed out 2067 ms 29200 KB Time limit exceeded