Pagini recente » Cod sursa (job #511864) | Cod sursa (job #2076620) | Istoria paginii utilizator/mocke | Cod sursa (job #2073868) | Cod sursa (job #2683906)
#include <fstream>
#include <vector>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
vector <int> v;
vector <int> dp;
int n, p1, p2, LMAX = -1000000, x, nr, s;
int main()
{
f >> n;
for (int i=1; i<=n; i++)
{
f >> x;
v.push_back(x);
}
for (int i=1; i<v.size(); i++)
{
if (dp[i-1] + v[i] >= 0)
dp.push_back(dp[i-1] + v[i]);
else dp.push_back(v[i]), nr = i;
if (dp[i] > LMAX)
{
s = dp[i];
p1 = nr;
p2 = i;
}
}
g << s << ' ' << p1 << ' ' << p2 << '\n';
}