Cod sursa(job #2278807)
Utilizator | Bogdan Marin bogdanmarin69 | Data | 8 noiembrie 2018 16:26:43 |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
#include <fstream>
using namespace std;
ifstream cin("ssm.in");
ofstream cout("ssm.out");
int main()
{
int n, smax = (1 << 31), stmax = 1, drmax = 1, s = 0, st = 1;
cin >> n;
for(int i = 1; i <= n; ++i) {
int x;
cin >> x;
s = s + x;
if(s > smax) {
smax = s;
stmax = st;
drmax = i;
}
if(s < 0) {
s = 0;
st = i + 1;
}
}
cout << smax << ' ' << stmax << ' ' << drmax;
return 0;
}