Cod sursa(job #2811790)
| Utilizator | Data | 3 decembrie 2021 08:59:08 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 85 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <bits/stdc++.h>
#define L 1000000000000000000
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int main(){
int n, i, i1, i2;
long long x, s, smax;
fin >> n;
smax = -L;
s = -1;
i1 = 1;
for (i = 0; i < n; i++){
fin >> x;
if (s < 0){
s = x;
i1 = i + 1;
}
else
s = s + x;
if (smax < s){
smax = s;
i2 = i + 1;
}
}
fout << smax << " " << i1 << " " << i2 << "\n";
return 0;
}
