Advertisement
Josif_tepe

Untitled

Mar 15th, 2024
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4.     ios_base::sync_with_stdio(false);
  5.    
  6.  
  7.     int n, k, s;
  8.     cin >> n >> k >> s;
  9.    
  10.     int niza[n];
  11.     for(int i = 0; i < n; i++) {
  12.         cin >> niza[i];
  13.     }
  14.     long long sum = 0;
  15.     for(int i = 0; i < k - 1; i++) {
  16.         sum += niza[i];
  17.     }
  18.    
  19.     int i = 0;
  20.     pair<long long, int> p[n];
  21.     for(int j = k - 1; j < n; j++) {
  22.         sum += niza[j];
  23.         p[i] = make_pair(sum, i);
  24.         sum -= niza[i];
  25.         i++;
  26.     }
  27.     sort(p, p + i);
  28.     long long res = 0;
  29.     for(int j = i - 1; j >= max(0, i - 5000); j--) {
  30.         long long s_sum = 0;
  31.         int cnt = 1;
  32.         for(int idx = p[j].second; idx < p[j].second + k; idx++) {
  33.             if(cnt == s) {
  34.                 s_sum += niza[idx];
  35.                 cnt = 0;
  36.             }
  37.             cnt++;
  38.         }
  39.         if(res < p[j].first - s_sum) {
  40.             res = p[j].first - s_sum;
  41.         }
  42.     }
  43.     cout << res << endl;
  44.    
  45.    
  46.     return 0;
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement