Cod sursa(job #677980)
| Utilizator | Data | 10 februarie 2012 21:00:39 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 85 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.63 kb |
#include <iostream>
#include <fstream>
#include <cctype>
#define IN "ssm.in"
#define OUT "ssm.out"
using namespace std;
int main()
{
int n,max = -0xfffffff,sum = -1,x,beg,end;
ifstream fin(IN);
fin>>n;
for(int i=1;i<=n;++i)
{
fin>>x;
if(sum < 0 )
{
sum = x;
beg = i;
}
else
sum += x;
if(max < sum)
{
end = i;
max = sum;
}
}
fin.close();
ofstream fout(OUT);
fout << max <<" "<< beg <<" "<<end;
fout.close();
return 0;
}