Skip to content

Commit 39b89f5

Browse files
authored
[20251006] PGM / Lv2 / 퍼즐 게임 챌린지 / 김수연
[20251006] PGM / Lv2 / 퍼즐 게임 챌린지 / 김수연
2 parents 1e1cc04 + 07301c0 commit 39b89f5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
```java
2+
class Solution {
3+
public int solution(int[] diffs, int[] times, long limit) {
4+
int answer = 0;
5+
int start = 1;
6+
int end = 300000;
7+
while (start < end) {
8+
int mid = (start + end) / 2;
9+
long time = 0;
10+
for (int i = 0; i < diffs.length; i++) {
11+
if (diffs[i] <= mid) time += times[i];
12+
else {
13+
int wrong = diffs[i] - mid;
14+
if (i == 0) time += (times[0] * wrong + times[i]);
15+
else time += ((times[i]+times[i-1]) * wrong + times[i]);
16+
}
17+
}
18+
if (time <= limit) end = mid;
19+
else start = mid + 1;
20+
}
21+
return start;
22+
}
23+
}
24+
```

0 commit comments

Comments
 (0)