Pagini recente » Cod sursa (job #1086439) | Cod sursa (job #2950741) | Cod sursa (job #837706) | Cod sursa (job #1348497) | Cod sursa (job #2373508)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int crt,n,maxx,p,u;
int main()
{
int x,pc;
f>>n;
pc=1;
maxx=-1000;
for(int i=1; i<=n; i++)
{
f>>x;
//if(maxx<x) {maxx=x; p=u=i;}
if(x>=0)
crt+=x;
else
{
if(maxx<crt) {maxx=crt; p=pc; u=i-1;}
if(crt+x>0) crt+=x;
else {crt=0; pc=i+1;}
}
}
if(maxx<crt) {maxx=crt; p=pc; u=n;}
g<<maxx<<' '<<p<<' '<<u<<'\n';
return 0;
}