Skip to content

Commit 3190b13

Browse files
authored
[20250203] BOJ / 골드5 / 시간 관리 / 설진영
1 parent ac95a53 commit 3190b13

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws Exception {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int N = Integer.parseInt(br.readLine());
9+
Pair[] pairs = new Pair[N];
10+
11+
for (int i = 0; i < N; i++) {
12+
StringTokenizer st = new StringTokenizer(br.readLine());
13+
int t = Integer.parseInt(st.nextToken());
14+
int s = Integer.parseInt(st.nextToken());
15+
pairs[i] = new Pair(t, s);
16+
}
17+
18+
Arrays.sort(pairs, (x, y) -> x.s - y.s);
19+
20+
21+
int nowTime = 0;
22+
Integer ans = null;
23+
for (Pair p : pairs) {
24+
nowTime += p.t;
25+
26+
if (nowTime > p.s) {
27+
System.out.println(-1);
28+
return;
29+
}
30+
31+
if (ans == null) {
32+
ans = p.s - nowTime;
33+
} else {
34+
ans = Math.min (ans, p.s - nowTime);
35+
}
36+
}
37+
38+
System.out.println(ans);
39+
}
40+
41+
static class Pair {
42+
int t;
43+
int s;
44+
45+
public Pair(int t, int s) {
46+
this.t = t;
47+
this.s = s;
48+
}
49+
}
50+
}
51+
52+
```

0 commit comments

Comments
 (0)