Pagini recente » Cod sursa (job #837699) | Cod sursa (job #2527334) | Cod sursa (job #2198304) | Cod sursa (job #1583270) | Cod sursa (job #2640875)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
const int nMax = 6000005;
long long sp[nMax], nr, minSecv, maxSecv;
int n, pozMinSecv, pozMaxSecv;
int main(){
ifstream fin("ssm.in");
ofstream fout("ssm.out");
fin >> n;
fin >> sp[0];
minSecv = sp[0];
maxSecv = sp[0];
for(int i = 1; i < n; ++i){
fin >> nr;
sp[i] = sp[i-1] + nr;
if(minSecv > sp[i]){
minSecv = sp[i];
pozMinSecv = i;
}
else if(maxSecv < sp[i]){
maxSecv = sp[i];
pozMaxSecv = i;
}
}
fout << maxSecv - minSecv << " " << pozMinSecv + 2<< " " << pozMaxSecv + 1<< "\n";
return 0;
}