Cod sursa(job #2813370)
Utilizator | Andreea Chivu andreea_chivu | Data | 6 decembrie 2021 15:01:00 |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.71 kb |
#include <iostream>
#include <fstream>
using namespace std;
#define INF -2000
int main()
{
ifstream fin("ssm.in");
ofstream fout("ssm.out");
long long n;
fin >> n;
long long sc = -1;
long long smax = -INF;
long long st = 1;
long long stmax, drmax;
for(long long i = 1; i <= n; i++){
long long x;
fin >> x;
if(sc < 0){
sc = x;
st = 1;
}else{
sc+=x;
}
if(sc > smax){
smax = sc;
stmax = st;
drmax = i;
}
}
fout << smax << " " << stmax << " " << drmax;
fin.close();
fout.close();
return 0;
}