Cod sursa(job #2644755)
| Utilizator | Data | 25 august 2020 20:46:26 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 15 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.99 kb |
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int main() {
int n, x, maxx = 0, s, inc, sf;
vector<int> v;
fin >> n;
for (int i = 1; i <= n; i++) {
fin >> x;
v.push_back(x);
}
for (int i = 0; i < n; i++)
for (int j = i; j < n; j++) {
s = 0;
for (int k = i; k <= j; k++)
s += v[k];
if (s > maxx) {
maxx = s;
inc = i;
sf = j;
} else if (s == maxx)
if (i < inc) {
maxx = s;
inc = i;
sf = j;
} else if (i == inc)
if (j < sf) {
maxx = s;
inc = i;
sf = j;
}
}
fout << maxx << ' ' << inc + 1 << ' ' << sf + 1;
}