Cod sursa(job #2409555)
| Utilizator | Data | 19 aprilie 2019 10:55:08 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 80 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream in("ssm.in");
ofstream out("ssm.out");
int n,i;
in >> n;
int S=0, pos1, pos2, Smax=0, a;
long long Smin = 1000000000000;
for(i=1; i<=n; i++)
{
in >> a;
S += a;
if(S < Smin)
{
Smin = S;
pos1 = i + 1;
}
if(S > Smax)
{
Smax = S;
pos2 = i;
}
}
out << Smax - Smin << ' ' << pos1 << ' ' << pos2;
return 0;
}
