Pagini recente » Cod sursa (job #456103) | Cod sursa (job #371002) | Cod sursa (job #3270423) | Cod sursa (job #1136186) | Cod sursa (job #1405373)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n, maxim, start, x, y;
map <int, int> a, dp;
int main()
{
fin >> n;
for (int i = 1, x; i <= n; i++)
{
fin >> x;
a[i] = x;
}
dp[1] = a[1];
maxim = a[1];
start = 1;
x = y = 1;
for (int i = 2; i <= n; i++)
{
if (dp[i - 1] + a[i] >= a[i])
dp[i] = dp[i - 1] + a[i];
else
{
dp[i] = a[i];
start = i;
}
if (dp[i] > maxim)
{
maxim = dp[i];
x = start;
y = i;
}
}
fout << maxim << " " << x << " " << y;
return 0;
}