답안 #630867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
630867 2022-08-17T09:30:52 Z kyaruru 학교 설립 (IZhO13_school) Java 11
25 / 100
1816 ms 28332 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[]> 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]);
        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);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 8996 KB Output is correct
2 Correct 66 ms 9040 KB Output is correct
3 Correct 76 ms 9104 KB Output is correct
4 Incorrect 73 ms 9032 KB Output isn't correct
5 Incorrect 78 ms 8888 KB Output isn't correct
6 Incorrect 77 ms 9072 KB Output isn't correct
7 Incorrect 403 ms 15088 KB Output isn't correct
8 Correct 499 ms 14984 KB Output is correct
9 Incorrect 430 ms 15136 KB Output isn't correct
10 Incorrect 466 ms 15064 KB Output isn't correct
11 Incorrect 494 ms 15136 KB Output isn't correct
12 Incorrect 549 ms 15036 KB Output isn't correct
13 Incorrect 1006 ms 18156 KB Output isn't correct
14 Incorrect 1207 ms 20216 KB Output isn't correct
15 Incorrect 1152 ms 22396 KB Output isn't correct
16 Correct 1309 ms 24688 KB Output is correct
17 Incorrect 1563 ms 26172 KB Output isn't correct
18 Incorrect 1724 ms 27212 KB Output isn't correct
19 Incorrect 1457 ms 27248 KB Output isn't correct
20 Incorrect 1816 ms 28332 KB Output isn't correct