Pagini recente » Cod sursa (job #2648881) | Cod sursa (job #2648952) | Cod sursa (job #1513893) | Cod sursa (job #2370192) | Cod sursa (job #2342556)
#include <fstream>
std::ifstream fin("secv2.in") ;
std::ofstream fout("secv2.out") ;
int n,i,maxim(1 << 31),numar,s(-1),p2,p1,p,k,l,x[100005];
int main() {
fin>>n>>k ;
for (i = 1 ; i <= n ; ++ i) {
fin>>numar ;
x[i]=x[i - 1]+numar ;
}
for (i = 1 ; i <= n; i++) {
if (i>=k && s+(x[i] - x[i - 1]) < x[i] - x[i - k]) {
s = x[i]-x[i - k];
l=i-k+1;
} else {
s += (x[i] - x[i - 1]) ;
}
if (s > maxim && i >= k) {
p2 = i ;
p1 = l ;
maxim = s ;
}
}
fout << p1 << " " << p2 << " " << maxim;
return 0;
}