Skip to content

Commit

Permalink
Feat: Week012 1213 SlidingWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
TalkingPotato90 committed Dec 16, 2024
1 parent 36ff321 commit dda525a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions HanByeolKo/week012/Week012.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@
| 문제 | 분류 | 링크 |
|---------|---------------|---------------------------------------|
| 꿀 아르바이트 | 누적합, 슬라이딩 윈도우 | https://www.acmicpc.net/problem/12847 |

### 1213 - 슬라이딩 윈도우

| 문제 | 분류 | 링크 |
|--------|---------------|---------------------------------------|
| 게으른 백곰 | 누적합, 슬라이딩 윈도우 | https://www.acmicpc.net/problem/10025 |
42 changes: 42 additions & 0 deletions HanByeolKo/week012/day1213_SlidingWindow/Bj10025.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package week012.day1213_SlidingWindow;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Bj10025 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());

int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());

int range = 2 * k + 1;

int[] ice = new int[1000000];

for (int i = 0; i < n; i++) {
st = new StringTokenizer(br.readLine());
int g = Integer.parseInt(st.nextToken());
int x = Integer.parseInt(st.nextToken());
ice[x] += g;
}

int sum = 0;
for (int i = 0; i <= range && i < 1000000; i++) {
sum += ice[i];
}

int max = sum;

for (int i = range + 1; i < 1000000; i++) {
sum += ice[i];
sum -= ice[i - range - 1];
max = Math.max(sum, max);
}

System.out.println(max);
}
}

0 comments on commit dda525a

Please sign in to comment.