Cod sursa(job #2471366)
| Utilizator | Data | 10 octombrie 2019 19:51:42 | |
|---|---|---|---|
| Problema | Secventa 2 | Scor | 90 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.63 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("secv2.in");
ofstream fout("secv2.out");
int n,k,i,l,lm,poz,pozm,a[50001];
long long sum,best[50001];
int main()
{
fin>>n>>k;
sum=-25000;
pozm=1;
poz=1;
for(i=1; i<=n; i++)
{
fin>>a[i];
if(best[i-1]+a[i]>a[i])best[i]=best[i-1]+a[i],l++;
else
{
poz=i;
l=0;
best[i]=a[i];
}
if(best[i]>sum&&l+1>=k)
{
pozm=poz;
lm=l;
sum=best[i];
}
}
fout<<pozm<<" "<<pozm+lm<<" "<<sum;
return 0;
}
