Cod sursa(job #2181750)
Utilizator | Data | 21 martie 2018 20:27:22 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 95 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int n, a[6000100], l, bst = -INT_MAX, cur, st, dr;
int main(){
in >> n;
for(int i = 1; i <= n; i++)
in >> a[i];
l = 1;
for(int i = 1; i <= n; i++){
cur += a[i];
if(cur > bst){
bst = cur;
st = l;
dr = i;
}
if(cur <= 0){
cur = 0;
l = i + 1;
}
}
out << bst << ' ' << st << ' ' << dr;
return 0;
}