Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2559: 수열 #27

Open
minsoo0715 opened this issue Sep 25, 2023 · 0 comments
Open

2559: 수열 #27

minsoo0715 opened this issue Sep 25, 2023 · 0 comments
Assignees
Labels
#누적합 누적합 문제 @백준 백준(https://www.acmicpc.net) 문제 C/C++ c/c++로 해결한 문제들

Comments

@minsoo0715
Copy link
Owner

2559: 수열

소스 코드

아이디어

1차원 누적합 배열을 만들면 s[2] - s[1] = v[2]이고 s[3] - s[1] = v[3] + v[2]이다.
따라서 K일 동안의 합은 s[i] - s[i-K]로 나타낼 수 있다. 이에 대해서 최댓값을 구하면 된다.

구현

누적합을 구해서 sum[i] - sum[i-K]가 최대가 되는 구간을 구한다.

for(int i = K; i <= N; ++i) {
    max = std::max(max, s[i]-s[i-K]);
}
@minsoo0715 minsoo0715 added @백준 백준(https://www.acmicpc.net) 문제 C/C++ c/c++로 해결한 문제들 #누적합 누적합 문제 labels Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
#누적합 누적합 문제 @백준 백준(https://www.acmicpc.net) 문제 C/C++ c/c++로 해결한 문제들
Projects
None yet
Development

No branches or pull requests

1 participant