Pagini recente » Cod sursa (job #2981497) | Cod sursa (job #2001457) | Cod sursa (job #2981631) | Istoria paginii utilizator/monarchuwu | Cod sursa (job #2655445)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int main() {
int n, x, s, inc, sf, s_max = 0;
vector<int> v;
fin >> n;
for (int i = 1; i <= n; i++) {
fin >> x;
v.push_back(x);
}
/// solutie de complexitate O(n^2)
for (int i = 0; i < n; i++) {
s = 0;
for (int j = i; j < n; j++) {
s += v[j];
if (s > s_max) {
inc = i;
sf = j;
s_max = s;
}
}
}
fout << s_max << ' ' << inc + 1 << ' ' << sf + 1;
}