Pagini recente » Cod sursa (job #1180571) | Cod sursa (job #2849031) | Cod sursa (job #1405259) | Cod sursa (job #304675) | Cod sursa (job #3224912)
#include <bits/stdc++.h>
using namespace std;
#define TITLE "buline"
#define ll long long
#define MaxN 100010
ifstream f (TITLE".in");
ofstream g (TITLE".out");
int solve()
{
int n;
ll dpmax;
ll semn;
f>>n;
f>>dpmax>>semn;
if(semn==0)
dpmax*=-1;
ll dpmin=dpmax;
ll maxim=dpmax;
ll minim=dpmin;
ll EndPozMax=1, EndPozMin=1, LengthMax=1, LengthMin=1, AnsLenMax=1, AnsLenMin=1, TotalSum=dpmax;
for(int i=2; i<=n; i++)
{
ll a;
f>>a>>semn;
if(semn==0)
a*=-1;
TotalSum+=a;
if(dpmax+a>=a)
{
dpmax+=a;
LengthMax++;
}
else
{
dpmax=a;
LengthMax=1;
}
if(dpmin+a<=a)
{
dpmin+=a;
LengthMin++;
}
else
{
dpmin=a;
LengthMin=1;
}
if(dpmax>maxim)
{
EndPozMax=i;
AnsLenMax=LengthMax;
maxim=dpmax;
}
if(dpmin<minim)
{
EndPozMin=i;
AnsLenMin=LengthMin;
minim=dpmin;
}
}
minim=TotalSum-minim;
if(maxim>minim || minim==0)
{
g<<maxim<<' '<<EndPozMax-AnsLenMax+1<<' '<<AnsLenMax;
return 0;
}
if(minim>maxim)
{
g<<minim<<' '<<EndPozMin+1<<' '<<n-AnsLenMin;
return 0;
}
if(EndPozMax<EndPozMin+1)
{
g<<maxim<<' '<<EndPozMax<<' '<<AnsLenMax;
return 0;
}
if(EndPozMin+1<EndPozMax)
{
g<<minim<<' '<<EndPozMin+1<<' '<<n-AnsLenMin;
return 0;
}
if(AnsLenMax<n-AnsLenMin)
{
g<<maxim<<' '<<EndPozMax<<' '<<AnsLenMax;
return 0;
}
g<<minim<<' '<<EndPozMin+1<<' '<<n-AnsLenMin;
return 0;
return 0;
}
int main()
{
solve();
return 0;
}