Pagini recente » Cod sursa (job #284776) | Cod sursa (job #1340894) | Cod sursa (job #1122713) | Cod sursa (job #206007) | Cod sursa (job #2215141)
#include<iostream>
#include<fstream>
using namespace std;
ifstream f("secv2.in");
ofstream g("secv2.out");
int N,k;
int main(){
int i, a;
int start = 0, end = 0, sum = 0, best =-1<<31, mps = 1 << 30, mpsi = 1;
f >> N>> k;
for (i = 1; i <= N; i++) {
f >> a;
sum += a;
if (best < sum - mps) {
best = sum - mps;
start = mpsi + 1;
end = i;
}
if (mps > sum) {
mps = sum;
mpsi = i;
}
}
if(best >= k)
g << start << ' ' << end << ' ' << best;
return 0;
}