Cod sursa(job #2740638)
| Utilizator | Data | 13 aprilie 2021 17:54:52 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 5 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#include <fstream>
#include <vector>
#include <string>
#define ll long long
std::ifstream f("ssm.in");
std::ofstream o("ssm.out");
int main() {
ll smax, p1max = 0, p2max = 0;
ll s = 0, p1 = 0, p2 = 0;
ll i = 0;
ll n;
f>>n;
ll x;
f>>x;
s = x;
smax = x;
while(f>>x) {
i++;
s += x;
if(s > smax) {
p1max = p1;
p2max = p2;
smax = s;
}
if(s < 0) {
s = 0;
p1 = p2 = i + 1;
} else {
p2 = i;
}
}
o<<smax<<" "<<p1max + 1<<" "<<p2max + 1;
}