Pagini recente » Cod sursa (job #3148703) | Cod sursa (job #2291641) | Cod sursa (job #567673) | Cod sursa (job #1870889) | Cod sursa (job #1276269)
#include <stdio.h>
#include <limits.h>
using namespace std;
int main() {
FILE *fin,*fout;
fin=fopen("ssm.in","r");
fout=fopen("ssm.out","w");
int i,n,x,smax=INT_MIN,stcur=1,drcur=0,best=0,stmax,drmax;
stmax=1;
drmax=1;
fscanf(fin,"%d",&n);
for(i=1; i<=n; i++) {
fscanf(fin,"%d",&x);
if(best+x>=x)
{
drcur=i;
best+=x;
}
else if(x>=best+x){
stcur=drcur=i;
best=x;
}
if(best>smax) {
smax=best;
stmax=stcur;
drmax=drcur;
}
}
fprintf(fout,"%d %d %d",smax,stmax,drmax);
return 0;
}