Pagini recente » Cod sursa (job #1146643) | Cod sursa (job #1043977) | Cod sursa (job #1083263) | Cod sursa (job #1148799) | Cod sursa (job #2943668)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n, nr[6000001], sum[6000001], i, mini, maxi;
int minn =2147483647, maxx = -2147483648;
int main()
{
fin >> n;
sum[0] = 0;
for (i = 1; i <= n; ++i){
fin >> nr[i];
sum[i] = sum[i-1]+nr[i];
}
for (i = 0; i <= n; ++i){
if (sum[i] > maxx){
maxx = sum[i];
maxi = i;
}
if (sum[i] < minn){
minn = sum[i];
mini = i;
}
}
fout << maxx - minn << ' ' << mini+1 << ' ' << maxi << '\n';
return 0;
}