Cod sursa(job #2775135)
| Utilizator | Data | 14 septembrie 2021 16:26:51 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.79 kb |
#include <fstream>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int n, max_so_far, curr_max, x;
int main(){
in >> n;
in >> x;
int left = 1, right = 1, p = 0;
curr_max = x;
max_so_far = x;
for(int i = 2; i <= n; i++) {
in >> x;
if(0 > curr_max) {
curr_max = x;
p = i;
}else{
curr_max += x;
}
if(max_so_far < curr_max) {
max_so_far = curr_max;
left = p;
right = i;
}
}
out << max_so_far << ' ' << left << ' ' << right;
return 0;
}
