Cod sursa(job #2450128)
Utilizator | Data | 21 august 2019 23:57:04 | |
---|---|---|---|
Problema | Secventa 2 | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.58 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream cin("secv2.in");
ofstream cout("secv2.out");
int n,k,st,dr;
long long int s,Max=-2000000000;
cin>>n>>k;
int v[n+1];
for (int i=1; i<=n; i++) cin>>v[i];
for (int i=1; i<=n-k; i++)
{
s=0;
for (int j=i; j<=n; j++)
{s+=v[j];
if (s>Max && j-i+1>=k)
{
Max=s;
st=i;
dr=j;
}
}
}
cout<<st<<" "<<dr<<" "<<Max;
return 0;
}