Pagini recente » Cod sursa (job #3266127) | Cod sursa (job #729899) | Cod sursa (job #2759839) | Cod sursa (job #575203) | Cod sursa (job #1577523)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("secv2.in");
ofstream cout("secv2.out");
const int MAXN = 7000005;
int main(void) {
int n, S,i,k;
int bestSum = -int(2e9), sum = 0, beg, end, idx;
cin >> n;
cin>>k;
for(i=1;i<=n;i++) {
cin >> S;
if (sum < 0)
sum = S, idx = i;
else
sum += S;
if (bestSum < sum&& i-idx>=k)
bestSum = sum, beg = idx, end = i;
}
cout << beg<<" " << end<<" "<<bestSum;
cin.close(), cout.close();
return 0;
}