Pagini recente » Cod sursa (job #1554136) | Cod sursa (job #925963) | Cod sursa (job #1936435) | Cod sursa (job #1245876) | Cod sursa (job #422639)
Cod sursa(job #422639)
#include <cstdio>
//<parsing>
FILE* fin=fopen("ssm.in","rb");
const unsigned maxb=8192;
char buf[maxb];
unsigned ptr=maxb;
inline int getInt(){
int nr=0,mul=1;
while(buf[ptr]<'0'||'9'<buf[ptr]){
if(buf[ptr]=='-'){
mul=-1;
}
if(++ptr>=maxb)
fread(buf,maxb,1,fin),ptr=0;
}
while('0'<=buf[ptr]&&buf[ptr]<='9'){
nr=nr*10+buf[ptr]-'0';
if(++ptr>=maxb)
fread(buf,maxb,1,fin),ptr=0;
}
return nr*mul;
}
//</parsing>
FILE* fout=fopen("ssm.out","w");
#define MAX 6000000
int n,vec[MAX],min;
int main(){
n=getInt();
int min=0,best=-(2<<29),beg=0,idx,end;
for(int i=1;i<=n;i++){
vec[i]=getInt();
vec[i]+=vec[i-1];
if(best<vec[i]-min){
best=vec[i]-min,beg=idx,end=i;
}
if(vec[i]<min){
idx=i+1,min=vec[i];
}
}
fprintf(fout,"%d %d %d",best,beg,end);
fclose(fin);
fclose(fout);
return 0;
}