Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- int main() {
- ios_base::sync_with_stdio(false);
- int n, k, s;
- cin >> n >> k >> s;
- vector<int> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- }
- ll sum = 0;
- for(int i = 0; i < k - 1; i++) {
- sum += v[i];
- }
- int j = 0;
- vector<pair<ll, int>> max_sums;
- for(int i = k - 1; i < n; i++) {
- sum += v[i];
- max_sums.push_back(make_pair(sum, j));
- sum -= v[j];
- j++;
- }
- sort(max_sums.rbegin(), max_sums.rend());
- ll res = 0;
- int till = min((int) max_sums.size(), 7000);
- for(int i = 0; i < till; i++) {
- ll tmp_sum = 0;
- for(j = max_sums[i].second + s - 1; j <= max_sums[i].second + k - 1; j += s) {
- tmp_sum += v[j];
- }
- res = max(res, max_sums[i].first - tmp_sum);
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement