Pagini recente » Cod sursa (job #1673388) | Cod sursa (job #1346577) | Cod sursa (job #1933900) | Cod sursa (job #2042335) | Cod sursa (job #3201903)
#include <bits/stdc++.h>
using namespace std;
#define TITLE "ssm"
ifstream f (TITLE".in");
ofstream g (TITLE".out");
#define INFINITE -(2^32+1)
int main()
{
int n;
f>>n;
pair<int,int> best;
int a;
f>>a;
best=make_pair(0,a);
long long int maxim=a,stanga=1,dreapta=1;
for(int i=1; i<n; i++)
{
f>>a;
if(a>=best.second+a)
best=(make_pair(i+1,a));
else
{
if(best.second+a==0)
best=(make_pair(i+1,0));
else
best=(make_pair(best.first,best.second+a));
}
if(best.second>maxim)
{
maxim=best.second;
stanga=best.first;
dreapta=i+1;
}
else if(best.second==maxim)
{
if(best.first<stanga)
{
stanga=best.first;
dreapta=i+1;
}
}
}
g<<maxim<<' '<<stanga<<' '<<dreapta;
return 0;
}