Pagini recente » Borderou de evaluare (job #3361562) | Cod sursa (job #3363501) | Cod sursa (job #1422014) | Monitorul de evaluare | Cod sursa (job #3363809)
#include <fstream>
using namespace std;
int a[6000010];
int main()
{
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n;
fin >> n;
for (int i = 1; i <= n; ++i)
{
fin >> a[i];
a[i] += a[i - 1];
}
int smax = a[1];
int start = 1;
int stop = 1;
int pozmin = 0;
if (a[1] < a[pozmin])
pozmin = 1;
for (int j = 2; j <= n; ++j)
{
int suma_cand = a[j] - a[pozmin];
if (suma_cand > smax)
{
smax = suma_cand;
start = pozmin + 1;
stop = j;
}
if (a[j] < a[pozmin])
{
pozmin = j;
}
}
fout << smax << " " << start << " " << stop << "\n";
return 0;
}