Pagini recente » Cod sursa (job #1609615) | Cod sursa (job #454617) | Cod sursa (job #1470429) | Cod sursa (job #2223408) | Cod sursa (job #1363053)
#include <iostream>
#include <fstream>
using namespace std;
int N, s[6000000], aux[6000000];
ifstream in("ssm.in");
ofstream out("ssm.out");
int main()
{
int i, min = int(2e9), poz_min = 0, max = -min, poz_max = 0;
in >> N;
for(i = 1; i <= N; i++)
{
in >> s[i];
}
/* magic here*/
aux[1] = s[1];
for(i = 2; i <= N; i++)
{
aux[i] = aux[i - 1] + s[i];
if(max < aux[i] - min ) {
max = aux[i];
poz_max = i;
}
if(min > aux[i]) {
min = aux[i];
poz_min = i;
}
}
cout<< aux[poz_max] - aux[poz_min] << " " << poz_min + 1 << " " << poz_max << "\n";
return 0;
}