Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* d164 */
- /* AC (23ms, 108KB) */
- #include <cstdio>
- #define max(x, y) ((x) > (y) ? (x) : (y))
- using namespace std;
- const int MAXN = 10001;
- int N, M, arr[MAXN], l ,r;
- long long ans, nex;
- int main()
- {
- while(~scanf("%d %d", &N, &M))
- {
- ans = l = 0, r = -1;
- for(int i = 0; i < N && scanf("%d", arr + i); ++i);
- while(r - l + 1 != M) ans += arr[++r];
- nex = ans + arr[(r + 1) % N] - arr[l];
- ans = max(ans, nex);
- ++r, ++l;
- r %= N, l %= N;
- while(r != M - 1)
- {
- nex = nex + arr[(r + 1) % N] - arr[l];
- ans = max(ans, nex);
- ++r, ++l;
- r %= N, l %= N;
- }
- printf("%lld\n", ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement