Pagini recente » Cod sursa (job #566937) | Cod sursa (job #591790) | Cod sursa (job #1912305) | Cod sursa (job #1114077) | Cod sursa (job #2643060)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
int n, k, nr, v[50005];
int main(){
//ifstream fin("date.in");
ifstream fin("secv2.in");
ofstream fout("secv2.out");
fin >> n >> k;
for(int i = 1; i <= n; ++i){
fin >> nr;
v[i] += v[i-1] + nr;
// cout << v[i] << " ";
}
int maxim = INT_MIN;
int minim = v[1], posMinim = 0;
pair<int,int> posMaxim;
for(int i = 1; i <= n - k + 1; ++i){
if(maxim < v[i + k - 1] - v[posMinim] && (i+k-1) - posMinim >= k ){
maxim = v[i + k - 1] - v[posMinim];
posMaxim.first = i + k - 1;
posMaxim.second = posMinim;
}
if(minim > v[i]){
posMinim = i;
minim = v[i];
}
//cout << posMinim << " " << i + k - 1<< "\n";
}
fout <<posMaxim.second + 1<< " " << posMaxim.first << " " << maxim ;
return 0;
}