Pagini recente » Cod sursa (job #2143303) | Cod sursa (job #2648767) | Cod sursa (job #1323355) | Cod sursa (job #1170345) | Cod sursa (job #2611069)
#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++;}
if(s > smax){
smax = s;
poz = i;
lmax = l;
}
} else
{
s += v[i];
l++;
}
}
int i = poz - l + 1;
fout << smax << ' ' << i << ' ' << poz;
fin.close(); fout.close();
return 0;
}