Pagini recente » Cod sursa (job #368112) | Statistici bad the ghoul (badghoul) | Cod sursa (job #1493046) | Cod sursa (job #1151764) | Cod sursa (job #1337891)
#include <iostream>
#include <vector>
#include <fstream>
#define inf (1<<30)
using namespace std;
int main()
{
ifstream f("secv2.in");
ofstream g("secv2.out");
int n,k,st,dr,max=-inf,x,p;
vector<int> v;
v.push_back(0);
st=0;
f >> n >> k;
for(int i=1; i<k; i++)
{
f >> x;
v.push_back(v[i-1]+x);
}
for(int i=k; i<=n; i++)
{
f >> x;
v.push_back(v[i-1]+x);
if (v[i-k]<v[st]) st=i-k;
if (v[i]-v[st]>max)
{
max=v[i]-v[st];
dr=i;
p=st+1;
}
}
g << p <<" " << dr << " " << max;
f.close();
g.close();
return 0;
}