Cod sursa(job #2648157)
Utilizator | Andrei Croitoriu Andreibatman | Data | 9 septembrie 2020 01:26:13 |
---|---|---|---|
Problema | Secventa 2 | Scor | 90 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.82 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("secv2.in");
ofstream fout("secv2.out");
long long n,i,j,s,k,st,dr,smax=LLONG_MIN,stmax,drmax,x;
int main()
{
fin>>n>>k;
st=1;
for(i=1;i<=n;i++)
{
fin>>x;
if(dr-st+1>=k && smax<s)
{
smax=s;
stmax=st;
drmax=dr;
}
if(x>s+x)
{
if(dr-st+1>=k && smax<s)
{
smax=s;
stmax=st;
drmax=dr;
}
s=x;
st=dr=i;
}
else
{
dr++;
s+=x;
}
}
if(n-st+1>=k && smax<s)
{
smax=s;
stmax=st;
drmax=n;
}
fout<<stmax<<" "<<drmax<<" "<<smax;
return 0;
}