Mai intai trebuie sa te autentifici.
Cod sursa(job #2568699)
| Utilizator | Data | 4 martie 2020 09:31:03 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.76 kb |
#include <fstream>
/// minim un element pozitiv
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int N, a[6000005], poz_i, poz_j, smax;
void citire()
{
f>> N;
for(int i=1; i<=N; ++i)
f>> a[i];
f.close();
}
void solutie()
{
int s, aux;
s=0;
smax=INT_MIN;
aux=1;
for(int i=1; i<=N; ++i)
{
s+=a[i];
if(s>smax)
{
smax=s;
poz_i=aux;
poz_j=i;
}
else if(s<0)
{
s=0;
aux=i+1;
}
}
}
void afisare()
{
g<< smax << ' ' << poz_i << ' ' << poz_j;
g.close();
}
int main()
{
citire();
solutie();
afisare();
return 0;
}
