Pagini recente » Cod sursa (job #2126023) | Cod sursa (job #51162) | Cod sursa (job #2266059) | Borderou de evaluare (job #895087) | Cod sursa (job #2165014)
#include<fstream>
#include<limits.h>
using namespace std;
ifstream f("secv2.in");
ofstream o("secv2.out");
int n, a[60000001], maxx, maxc, start, endd, s=0, k;
void citire(){
f>>n>>k;
for(int i=0;i<n;i++){
f>>a[i];
}
}
void kadane(){
maxx=INT_MIN;
maxc=0;
for(int i=0;i<n;i++){
maxc+=a[i];
if(maxx<maxc){
start=s;
endd=i;
if((endd-start)>=k){
maxx=maxc;
}
}
if(maxc<0){
maxc=0;
s=i+1;
}
}
}
void afisare(){
o<<++start<<" "<<++endd<<" "<<maxx;
}
int main(){
citire();
kadane();
afisare();
}