Advertisement
Emiliatan

d164

May 23rd, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. /* d164             */
  2. /* AC (23ms, 108KB) */
  3. #include <cstdio>
  4. #define max(x, y) ((x) > (y) ? (x) : (y))
  5.  
  6. using namespace std;
  7.  
  8. const int MAXN = 10001;
  9.  
  10. int N, M, arr[MAXN], l ,r;
  11. long long ans, nex;
  12.  
  13. int main()
  14. {
  15.     while(~scanf("%d %d", &N, &M))
  16.     {
  17.         ans = l = 0, r = -1;
  18.         for(int i = 0; i < N && scanf("%d", arr + i); ++i);
  19.         while(r - l + 1 != M) ans += arr[++r];
  20.  
  21.         nex = ans + arr[(r + 1) % N] - arr[l];
  22.         ans = max(ans, nex);
  23.         ++r, ++l;
  24.         r %= N, l %= N;
  25.  
  26.         while(r != M - 1)
  27.         {
  28.             nex = nex + arr[(r + 1) % N] - arr[l];
  29.             ans = max(ans, nex);
  30.             ++r, ++l;
  31.             r %= N, l %= N;
  32.         }
  33.         printf("%lld\n", ans);
  34.     }
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement