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]);
PriorityQueue<int[]> save=new PriorityQueue<>((o1, o2) -> o2[0]-o1[0]);
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]){
save.add(s.poll());
s.add(k[i]);
}
}
}
}
}
long sum=0;
while(!m.isEmpty()) save.add(m.poll());
while(p-->0) sum+=save.poll()[0];
while(!s.isEmpty()) sum+=s.poll()[1];
System.out.println(sum);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
8988 KB |
Output is correct |
2 |
Correct |
74 ms |
8952 KB |
Output is correct |
3 |
Correct |
83 ms |
8912 KB |
Output is correct |
4 |
Incorrect |
82 ms |
8760 KB |
Output isn't correct |
5 |
Incorrect |
80 ms |
9008 KB |
Output isn't correct |
6 |
Incorrect |
87 ms |
8632 KB |
Output isn't correct |
7 |
Incorrect |
525 ms |
14992 KB |
Output isn't correct |
8 |
Correct |
466 ms |
14824 KB |
Output is correct |
9 |
Incorrect |
490 ms |
15116 KB |
Output isn't correct |
10 |
Incorrect |
523 ms |
14808 KB |
Output isn't correct |
11 |
Incorrect |
547 ms |
14876 KB |
Output isn't correct |
12 |
Incorrect |
565 ms |
14824 KB |
Output isn't correct |
13 |
Incorrect |
1133 ms |
18776 KB |
Output isn't correct |
14 |
Incorrect |
1120 ms |
20696 KB |
Output isn't correct |
15 |
Correct |
1357 ms |
24088 KB |
Output is correct |
16 |
Correct |
1447 ms |
25260 KB |
Output is correct |
17 |
Incorrect |
1884 ms |
32136 KB |
Output isn't correct |
18 |
Execution timed out |
2065 ms |
32664 KB |
Time limit exceeded |
19 |
Incorrect |
1896 ms |
30028 KB |
Output isn't correct |
20 |
Execution timed out |
2070 ms |
32048 KB |
Time limit exceeded |