Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- int n, k, s;
- cin >> n >> k >> s;
- int niza[n];
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- }
- long long sum = 0;
- for(int i = 0; i < k - 1; i++) {
- sum += niza[i];
- }
- int i = 0;
- pair<long long, int> p[n];
- for(int j = k - 1; j < n; j++) {
- sum += niza[j];
- p[i] = make_pair(sum, i);
- sum -= niza[i];
- i++;
- }
- sort(p, p + i);
- long long res = 0;
- for(int j = i - 1; j >= max(0, i - 5000); j--) {
- long long s_sum = 0;
- int cnt = 1;
- for(int idx = p[j].second; idx < p[j].second + k; idx++) {
- if(cnt == s) {
- s_sum += niza[idx];
- cnt = 0;
- }
- cnt++;
- }
- if(res < p[j].first - s_sum) {
- res = p[j].first - s_sum;
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement