Cod sursa(job #2230125)
| Utilizator | Data | 9 august 2018 10:22:59 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 95 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
#include <bits/stdc++.h>
using namespace std;
int n, poz1, poz1max, poz2, maxx, i, x, s = -INT_MAX;
int main()
{
ifstream f("ssm.in");
ofstream g("ssm.out");
f >> n;
poz1 = 1;
for(i = 1;i <= n;i++)
{
f >> x;
if(s < 0)s = x, poz1 = i;
else s = s + x;
if(s > maxx)maxx = s , poz2 = i , poz1max = poz1;
}
g << maxx << " " << poz1max << " " << poz2;
return 0;
}
