Cod sursa(job #2951161)
| Utilizator | Data | 5 decembrie 2022 16:21:37 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.67 kb |
#include <bits/stdc++.h>
using namespace std;
int n[6000005], bonga[6000005], y, smax = 0, st, dr;
int main()
{
cin >> y;
cin >> n[1];
bonga[1] = n[1];
for(int i = 2; i <= y; i++){
cin >> n[i];
bonga[i] = n[i];
}
for(int i =1 ;i <=y; i++){
if(bonga[i] < n[i] + bonga[i - 1]){
bonga[i] = bonga[i - 1] + n[i];
}
if(smax < bonga[i]){
smax = bonga[i];
dr = i;
}
}
for(int i = dr; i >= 1; i--){
if(bonga[i] <= 0){
st = i;
break;
}
}
cout << smax << " " << st + 1 << " " << dr;
return 0;
}
