Skip to content

Instantly share code, notes, and snippets.

@hrs113355
Created December 4, 2014 17:16
Show Gist options
  • Save hrs113355/fecd81756ea568293d0e to your computer and use it in GitHub Desktop.
Save hrs113355/fecd81756ea568293d0e to your computer and use it in GitHub Desktop.
paiza_3.cpp
#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