Cod sursa(job #1573630)
Utilizator | Goje Samuel Andrei Daniel pringon | Data | 19 ianuarie 2016 20:26:35 |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.56 kb |
#include <fstream>
using namespace std;
int main()
{
ifstream in;
in.open("z.in");
ofstream out;
out.open("z.out");
int n, x, smax = -20000000, stmax, sfmax, sc=-1, stc, sfc=0;
in>>n;
for(int i = 1;i<=n;i++){
in>>x;
if(sc < 0){
sc = 0;
stc = sfc+1;
}
sc += x;
sfc += 1;
if(sc > smax){
smax = sc;
stmax = stc;
sfmax = sfc;
}
}
out<<smax<<" "<<stmax<<" "<<sfmax;
in.close();
out.close();
return 0;
}