Submission #2912994

Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
using ll = long long;

int main() {
	int N, K; cin >> N >> K;
	vector<int> a(N);
	rep(i, N) {
		scanf("%d", &a[i]);
	}
	vector<ll> dp(N + 1), ma(N + 1);
	for (int i = 1; i <= N; i++) {
		dp[i] = dp[i - 1] + a[i - 1];
		if (i >= K) {
			dp[i] = max(dp[i], ma[i - K]);
		}
		ma[i] = max(ma[i - 1], dp[i]);
	}
	cout << dp[N] << endl;
}

Submission Info

Submission Time
Task B - Neutralize
User sugim48
Language C++14 (GCC 5.4.1)
Score 400
Code Size 489 Byte
Status
Exec Time 28 ms
Memory 4096 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:12:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
                     ^

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 a01, a02, a03, a04
All 400 / 400 a01, a02, a03, a04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44
Case Name Status Exec Time Memory
a01 1 ms 256 KB
a02 1 ms 256 KB
a03 1 ms 256 KB
a04 1 ms 256 KB
b05 1 ms 256 KB
b06 1 ms 256 KB
b07 4 ms 640 KB
b08 28 ms 4096 KB
b09 28 ms 4096 KB
b10 28 ms 4096 KB
b11 28 ms 4096 KB
b12 1 ms 256 KB
b13 23 ms 4096 KB
b14 23 ms 4096 KB
b15 27 ms 4096 KB
b16 27 ms 4096 KB
b17 27 ms 4096 KB
b18 27 ms 4096 KB
b19 27 ms 4096 KB
b20 23 ms 3840 KB
b21 22 ms 4096 KB
b22 26 ms 4096 KB
b23 26 ms 4096 KB
b24 19 ms 3328 KB
b25 22 ms 4096 KB
b26 25 ms 4096 KB
b27 21 ms 4096 KB
b28 22 ms 4096 KB
b29 21 ms 4096 KB
b30 15 ms 2432 KB
b31 24 ms 4096 KB
b32 21 ms 3968 KB
b33 18 ms 3456 KB
b34 22 ms 3840 KB
b35 27 ms 4096 KB
b36 28 ms 4096 KB
b37 28 ms 4096 KB
b38 28 ms 4096 KB
b39 28 ms 4096 KB
b40 28 ms 4096 KB
b41 28 ms 4096 KB
b42 28 ms 4096 KB
b43 28 ms 4096 KB
b44 28 ms 4096 KB