Cod sursa(job #3195598)
| Utilizator | Data | 21 ianuarie 2024 12:54:27 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 95 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.67 kb |
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int main()
{
int n;
long long summax = 0;
f >> n;
int v;
long long s = -1;
int st = 1, dr = 1;
int stmax = 1, drmax = 1;
for( int i = 1; i <= n; ++i )
{
f >> v;
if( s < 0 )
{
s = v;
st = i;
dr = i;
}
else
{
s = s+v;
dr = i;
}
if( summax < s )
{
summax = s;
stmax = st;
drmax = dr;
}
}
g << summax << " " << stmax << " " << drmax << " ";
return 0;
}
