[백준 c++] 2559 수열

jw·2022년 2월 6일
0

백준

목록 보기
8/141
post-thumbnail

문제 설명

https://www.acmicpc.net/problem/2559
누적합 이용하는 문제


전체 코드

#include <iostream>
#include <algorithm>
using namespace std;
int n,k,tmp,ret = -1000000;
int psum[100001]; //0으로 초기화 되는 구나^.^
int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> tmp;
		psum[i] = psum[i - 1] + tmp;
	}
	for (int i = k; i <= n; i++) {
		ret = max(ret, psum[i] - psum[i - k]);
	}
	cout << ret;
}
profile
다시태어나고싶어요

0개의 댓글

Powered by GraphCDN, the GraphQL CDN