Cod sursa(job #2078406)
| Utilizator | Data | 29 noiembrie 2017 15:42:26 | |
|---|---|---|---|
| Problema | Secventa 2 | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.65 kb |
#include <fstream>
using namespace std;
const int NMax=50005;
int x[NMax],N,i,poz,nr,st,dr,K;
ifstream fin("secv2.in");
ofstream fout("secv2.out");
void citire()
{
fin>>N>>K;
for(i=1;i<=N;i++)
{
fin>>x[i];
x[i]+=x[i-1];
}
}
void rezolva()
{
st=1;
dr=1;
dr=K;
nr=x[K];
for(int i=K+1;i<=N;i++)
{
if(x[i-K]<x[poz])
poz=i-K;
if(x[i]-x[poz]>nr)
{
nr=x[i]-x[poz];
st=poz+1;
dr=i;
}
}
fout<<st<<" "<<dr<<" "<<nr<<'\n';
}
int main()
{
citire();
rezolva();
return 0;
}
