Created
December 4, 2014 17:16
-
-
Save hrs113355/fecd81756ea568293d0e to your computer and use it in GitHub Desktop.
paiza_3.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<queue> | |
using namespace std; | |
int main(){ | |
queue<int> pad; | |
int t, n; | |
int sum = 0, max = 0; | |
cin >> t >> n; | |
for (int i = 0; i < t; i++) | |
{ | |
int x; | |
cin >> x; | |
pad.push(x); | |
if (i < t) | |
sum += x; | |
} | |
max = sum; | |
if (t != n) | |
{ | |
for (int i = t; i < n; i++) | |
{ | |
int x; | |
cin >> x; | |
sum -= pad.front(); | |
sum += x; | |
pad.push(x); | |
pad.pop(); | |
if (sum > max) | |
max = sum; | |
} | |
} | |
cout << max << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment