Skip to content

Commit 120b2c2

Browse files
authored
[20250203] BOJ / 골드5 / 시간 관리 / 김수연
1 parent 2e05f78 commit 120b2c2

File tree

1 file changed

+55
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)