Pagini recente » Cod sursa (job #2087533) | Cod sursa (job #2965617) | Cod sursa (job #3190445) | Cod sursa (job #254900) | Cod sursa (job #1452249)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
int n;
int a[6000001];
#ifdef home
ifstream fin("input.txt");
ofstream fout("output.txt");
#else
ifstream fin("ssm.in");
ofstream fout("ssm.out");
#endif
int good = -1;
int x = 0,y=0;
int main()
{
fin>>n;
for (int i = 1; i <= n; i++)
{
fin>>a[i];
good = max(good,a[i]);
}
a[0] = 0;
for (int i= 1; i<=n ;i++)
a[i] = a[i-1] +a[i];
int m = 0;
for (int i= 1; i<=n; i++)
{
if (a[i]-a[m]>good)
{
x = m; y=i;
good = a[i]-a[m];
}
if (a[i]<a[m]) m = i;
}
fout<<good<<' '<<x+1<<' '<<y;
return 0;
}