Mai intai trebuie sa te autentifici.
Cod sursa(job #2614990)
| Utilizator | Data | 13 mai 2020 01:01:08 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 80 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.73 kb |
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const char* inputFile = "ssm.in";
const char* outputFile = "ssm.out";
int main()
{
ifstream in(inputFile);
unsigned N, st, dr;
in >> N;
vector<int> v(N);
int smax, cmax;
smax = cmax = 0;
for(unsigned i = 0; i < N; ++i)
{
in >> v[i];
if(cmax + v[i] > 0)
cmax = cmax + v[i];
else{
st = i + 1;
cmax = 0;
}
if(cmax > smax)
{
smax = cmax;
dr = i;
}
}
in.close();
ofstream out(outputFile);
out << smax << ' ' << st + 1 << ' ' << dr + 1;
out.close();
return 0;
}
