Cod sursa(job #1088934)
Utilizator | Data | 20 ianuarie 2014 23:23:07 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include<fstream>
#include<climits>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int main()
{
int n,S=0,x,y,z,a=0,i,max=INT_MIN;
f>>n;
for(i=1;i<=n;i++)
{
f>>x;
if(S<0)
{
S=0;
a=i;
}
S+=x;
if(S>max)
{
y=a;
z=i;
max=S;
}
}
g<<max<<" "<<y<<" "<<z;
f.close();
g.close();
return 0;
}