Cod sursa(job #1723061)
| Utilizator | Data | 29 iunie 2016 17:17:39 | |
|---|---|---|---|
| Problema | Secventa 2 | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.63 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int best,imax1,imax2,jmax,i,j,n,x,maxi;
int main()
{
f>>n;
imax1=1; imax2=1;
jmax=0;
maxi=-2147483647;
best=0;
for(i=1;i<=n;i++)
{
f>>x;
if(x>best+x)
{
best=x;
imax1=i;
}
else
{
best=best+x;
}
if(best>maxi) imax2=imax1, jmax=i, maxi=best;
else if(best==maxi && imax1>imax2) imax2=imax1, jmax=i, maxi=best;
}
g<<maxi<<' '<<imax2<<' '<<jmax<<' ';
return 0;
}
