Pagini recente » Cod sursa (job #2926039) | Cod sursa (job #3246211)
/*
#include<fstream>
#include<algorithm>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
int main(){
int i,n,smax=0,s,st=1,v[1002],ii,jj;
fin>>n;
for(i=1;i<=n;i++){
fin>>v[i];
s=s+v[i];
while(s<0){
s=s-v[st];
st++;
}
if(smax<s){
smax=s;
ii=st;
jj=i;
}
}
fout<<smax<<" "<<ii<<" "<<jj;
}
*/
#include<fstream>
#include<algorithm>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
int main(){
int i,n,smax=0,s,st=0,x,dr=0,ii,jj,lg=0,lgmax;
fin>>n;
fin>>x;
s=smax=x;
lg=1;
lgmax=1;
st=1;
for(i=2;i<=n;i++){
fin>>x;
if(s+x>x){
s=s+x;
lg++;
}
else{
s=x;
lg=1;
}
if(s>smax){
smax=s;
lgmax=lg;
dr=i;
}
else{
if(s==smax){
if(lg<lgmax){
lgmax=lg;
dr=i;
}
}
}
}
fout<<smax<<" "<<dr-lgmax+1<<" "<<dr;
}