Pagini recente » Cod sursa (job #3004752) | Cod sursa (job #1795420) | Cod sursa (job #1079094) | Cod sursa (job #832902) | Cod sursa (job #2611160)
#include <iostream>
#include <fstream>
///T5
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
long long x, s, smax, n, poz, v[1000000], l , lmax;
int main()
{
fin >>n; fin >> v[1]; poz = 1;
s = smax = v[1]; l = lmax = 1;
for(int i = 2; i <= n; i++){
fin >> v[i];
if(v[i]>0){
if(s<0){
s = v[i];
l = 1;
} else {
s+= v[i];
l++;
}
} else {
s += v[i]; l++;
}
if(s > smax){
smax = s;
poz = i;
lmax = l;
}
}
int i = poz - lmax + 1;
fout << smax << ' ' << i << ' ' << poz;
fin.close(); fout.close();
return 0;
}