Pagini recente » Cod sursa (job #1572633) | Cod sursa (job #3198002) | Cod sursa (job #1406547) | Cod sursa (job #2585866) | Cod sursa (job #2124358)
#include <fstream>
#include <queue>
#include <iostream>
using namespace std;
ifstream f("secv2.in");
ofstream g("secv2.out");
queue <int>q;
int x,n,s[50001],i,max1,st,dr,k,mx,ss;
int main()
{
f>>n>>k;
for(i=1;i<=n;i++)
{
f>>x;
s[i]=s[i-1]+x;
}
q.push(1);
st=1;
dr=k;
mx=s[k];
for(i=k+1;i<=n;i++)
{
ss=s[i]-s[i-k];
while(!q.empty()&&s[i]-s[q.front()-1]<ss)
{
q.pop();
}
q.push(i-k+1);
ss=s[i]-s[q.front()-1];
if(ss>mx)
{
mx=ss;
st=q.front();
dr=i;
}
}
g<<st<<" "<<dr<<" "<<mx;
return 0;
}