Cod sursa(job #3235263)
Utilizator | Data | 16 iunie 2024 17:29:54 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 95 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
using namespace std;
int main()
{
ifstream cin ("ssm.in");
ofstream cout ("ssm.out");
int n, i, j, max = 0, stmax, drmax, x, s = 0, st;
cin >> n;
for(i = 1; i <= n; i++) {
cin >> x;
if(s < 0) {
s = 0;
st = i;
}
s += x;
if(max < s) {
max = s;
stmax = st;
drmax = i;
}
}
cout << max << " " << stmax << " " << drmax;
return 0;
}