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