-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathSolution.java
33 lines (24 loc) · 863 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
int numContests = scanner.nextInt();
int maxLoses = scanner.nextInt();
int maxLuck = 0;
List<Integer> importantContests = new ArrayList<>();
for (int i = 0; i < numContests; i++) {
int luck = scanner.nextInt();
int importance = scanner.nextInt();
maxLuck += luck;
if (importance == 1)
importantContests.add(luck);
}
scanner.close();
Collections.sort(importantContests);
for (int i = 0; i < importantContests.size() - maxLoses; i++) {
maxLuck -= 2 * importantContests.get(i);
}
System.out.println(maxLuck);
}
}