Pagini recente » Cod sursa (job #3314138) | Cod sursa (job #1509174) | Cod sursa (job #3334168) | Cod sursa (job #798854) | Cod sursa (job #1910047)
#include <iostream>
#include <fstream>
#define nmax 6000005
#define zeros(x) ((x^(x-1))&x)
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int a[nmax];
int n, x, y, m;
void citire()
{
f>>n;
for(int i=1; i<=n; ++i)
{
f>>a[i];
}
}
void dynamic_programming()
{
m=-int(2e9);
int s=0, ind;
for(int i=1; i<=n; ++i)
{
if(s<0)
{
ind=i;
s=a[i];
}
else
{
s+=a[i];
}
if(m<s)
{
m=s;
x=ind;
y=i;
}
}
}
int main()
{
citire();
dynamic_programming();
g<<m<<" "<<x<<" "<<y;
return 0;
}