답안 #630609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
630609 2022-08-16T16:07:24 Z kyaruru 학교 설립 (IZhO13_school) Java 11
25 / 100
2000 ms 51400 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]);
        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();
                tp--;
            }
            else {
                r = bb.poll();
                tq--;
            }
            ka[i][0]=r[0];
            ka[i][1]=r[1];
            use[r[2]]=true;
            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);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 8952 KB Output is correct
2 Correct 72 ms 8964 KB Output is correct
3 Correct 73 ms 8744 KB Output is correct
4 Incorrect 72 ms 8900 KB Output isn't correct
5 Incorrect 72 ms 8672 KB Output isn't correct
6 Incorrect 78 ms 9124 KB Output isn't correct
7 Incorrect 281 ms 14492 KB Output isn't correct
8 Correct 462 ms 15060 KB Output is correct
9 Incorrect 423 ms 15052 KB Output isn't correct
10 Incorrect 408 ms 15028 KB Output isn't correct
11 Incorrect 536 ms 15452 KB Output isn't correct
12 Incorrect 496 ms 15232 KB Output isn't correct
13 Incorrect 1346 ms 26592 KB Output isn't correct
14 Incorrect 1069 ms 24404 KB Output isn't correct
15 Incorrect 877 ms 30776 KB Output isn't correct
16 Correct 1451 ms 36156 KB Output is correct
17 Execution timed out 2085 ms 41016 KB Time limit exceeded
18 Incorrect 1783 ms 44888 KB Output isn't correct
19 Execution timed out 2082 ms 49640 KB Time limit exceeded
20 Execution timed out 2024 ms 51400 KB Time limit exceeded