Pagini recente » Cod sursa (job #232450) | Cod sursa (job #822590) | Cod sursa (job #457827) | Cod sursa (job #1615216) | Cod sursa (job #1847533)
#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, smax = 0;
cin>>n>>k;
best[0].s = -1;
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;
}