Cod sursa(job #1703097)
| Utilizator | Data | 16 mai 2016 10:50:13 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.73 kb |
#include <fstream>
using namespace std;
ifstream in ("ssm.in");
ofstream out ("ssm.out");
int main()
{
int n, i, S = 0, poz1 = 1, poz1max = 1, poz2max = 1, k = 0, a;
in >> n >> a;
poz1 = 1;
int Smax = a;
S = a;
if(S < 0) {
S = 0;
poz1 = 2;
}
for (i = 2; i <= n; i ++)
{
in >> a;
S = S + a;
if(a > Smax) {
Smax = a;
poz1max = poz2max = i;
}
if(S > Smax) {
Smax = S;
poz1max = poz1;
poz2max = i;
}
if(S < 0) {
S = 0;
poz1 = i + 1;
}
}
out << Smax << " " << poz1max << " " << poz2max;
return 0;
}
