SHARE
TWEET

Untitled

The_Law May 25th, 2020 1,233 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #define int long long
  4.  
  5. using namespace std;
  6.  
  7. int32_t main()
  8. {
  9.     int n, k;
  10.     cin >> n >> k;
  11.    
  12.     vector<int> moments(n);
  13.     int prev_max = 0;
  14.     int ans = 0;
  15.  
  16.     for (int i = 0; i < n; ++i) {
  17.         cin >> moments[i];
  18.         if (i - k >= 0) {
  19.             int condidate = moments[i - k];
  20.             prev_max = max(prev_max, condidate);
  21.             ans = max(ans, prev_max + moments[i]);
  22.         }
  23.     }
  24.  
  25.     cout << ans;
  26.     return 0;
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top