Pagini recente » Cod sursa (job #2396745) | Cod sursa (job #388474) | Cod sursa (job #3180595) | Cod sursa (job #2096156) | Cod sursa (job #1875025)
#include <fstream>
#include <vector>
#define nmax 6000005
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
const int inf = 0x3f3f3f3f;
int n, bestsum,stg,st,dr;
vector<int>best(nmax),a(nmax);
int main()
{ int i;
f>>n;
st=1;
dr=1;
bestsum=-inf;
for(i=1;i<=n;i++)
f>>a[i];
for(i=1;i<=n;i++)
{
best[i]=a[i];
if(best[i]<=best[i-1]+a[i])
best[i]=best[i-1]+a[i];
else
st=i;
if(bestsum<best[i])
{
stg=st;
bestsum=best[i];
dr=i;
}
}
g<<bestsum<<' '<<stg<<' '<<dr;
}