Pagini recente » Cod sursa (job #2428791) | Cod sursa (job #2982524) | Cod sursa (job #361499) | Cod sursa (job #938408) | Cod sursa (job #2150202)
#include <iostream>
#include <fstream >
using namespace std;
ifstream fin ("file.in");
ofstream fout ("file.out");
int main()
{
int n,S,smax,stmax,drmax,st,x;
fin >> n>> x;
S=smax=x;
stmax=drmax=st=1;
for (int i=2;i<=n;i++){
if (S<0){
S=0;
st=i;
}
fin >> x;
S=S+x;
if (S>smax){
smax=S;
stmax=st;
drmax=i;
}
}
fout << smax <<" "<< stmax << " "<<drmax;
return 0;
}