Cod sursa(job #2921076)
| Utilizator | Data | 27 august 2022 12:35:59 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 95 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.61 kb |
#include <fstream>
#include <iostream>
using namespace std;
ifstream f ("ssm.in");
ofstream g ("ssm.out");
const int NMAX = 1<<31;
int main()
{
long long int sc, smax;
sc = smax = NMAX;
int stmax, drmax, stc;
stc = stmax = drmax = -1;
int n;
f>>n;
for(int i=1; i<=n; i++){
int x;
f>>x;
if(sc<0){
sc = x;
stc = i;
}else{
sc+=x;
}
if(sc > smax){
smax = sc;
drmax = i;
stmax = stc;
}
}
g<<smax<<' '<<stmax<<' '<<drmax;
return 0;
}
