Cod sursa(job #3220424)
Utilizator | Tigau Alexandru AlexandruTigau | Data | 3 aprilie 2024 16:09:30 |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.64 kb |
#include <fstream>
#include <deque>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
struct afisare{
long long smax;
int st,dr;
}af;
int main()
{
int n,x,ind;
long long s=0,nrm=-2147483649;
deque <int> d;
af.smax=-2147483649;
f>>n;
for(int i=1;i<=n;i++)
{
if(s<0)
{
d.clear();
s=0;
}
f>>x;
if(x>nrm) nrm=x, ind=i;
s+=x;
d.push_front(i);
if(af.smax<s)
af={s,d.back(),d.front()};
}
if(nrm>af.smax) g<<nrm<<" "<<ind<<" "<<ind;
else g<<af.smax<<" "<<af.st<<" "<<af.dr;
return 0;
}