Cod sursa(job #3343354)
| Utilizator | Data | 27 februarie 2026 08:59:26 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
//#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
string file = "file";
ifstream f(file + ".in");
ofstream g(file + ".out");
int main()
{
long long n, x, i, sum = 0, st = 1, stmax = 0, drmax = 0, maxx = -2000000000;
f >> n;
for (i = 1; i <= n; i++)
{
f >> x;
if (sum < 0)
sum = x, st = i;
else
sum += x;
if (sum > maxx) {
maxx = sum;
stmax = st;
drmax = i;
}
}
g << maxx << " " << stmax << " " << drmax;
return 0;
}