Pagini recente » Cod sursa (job #638336) | Cod sursa (job #564892) | Cod sursa (job #545719) | Cod sursa (job #2907146) | Cod sursa (job #1847535)
#include <iostream>
#include <fstream>
using namespace std;
struct {
int s, l = 1;
} best[50001];
int main()
{
ifstream cin("secv2.in");
//ofstream cout("secv2.out");
int n, i, k, nr, pmax = 1, smax = 0;
cin>>n>>k;
best[0].s = 0;
best[0].l = 0;
for(i = 1; i <= n; ++i) {
cin>>nr;
if(nr > nr + best[i-1].s) {
best[i].s = nr;
} else {
best[i].s = nr + best[i-1].s;
best[i].l = best[i-1].l + 1;
if (best[i].l >= k && best[i].s > smax) {
smax = best[i].s;
pmax = i;
}
}
}
cout<<pmax - best[pmax].l + 1<<" "<<pmax<<" "<<best[pmax].s;
return 0;
}