Pagini recente » Cod sursa (job #3126564) | Autentificare | Cod sursa (job #897549) | Cod sursa (job #2001264) | Cod sursa (job #331381)
Cod sursa(job #331381)
#include<fstream>
#define dmax 6000003
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int sir[dmax],n,pr[dmax],p,u;
int temp[dmax],mx=-1;
int main()
{ int i;
in>>n;
for(i=1;i<=n;i++)
in>>sir[i];
in.close();
for(i=1;i<=n;i++)
{ if(i==1)
{ temp[i]=sir[i];
pr[i]=1;
}
else
{ temp[i]=max(sir[i],sir[i]+temp[i-1]);
if(temp[i]==sir[i])
pr[i]=i;
else if(temp[i]==sir[i]+temp[i-1])
pr[i]=pr[i-1];
}
}
for(i=1;i<=n;i++)
if((temp[i]>mx)||(mx==-1))
{ mx=temp[i];
p=pr[i];
u=i;
}
out<<mx<<" "<<p<<" "<<u;
out.close();
}