Pagini recente » Istoria paginii runda/120n | Cod sursa (job #2942442) | Istoria paginii runda/nicolae.gutza/clasament | Cod sursa (job #1903006) | Cod sursa (job #2469504)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("buline.in");
ofstream fout("buline.out");
int n,i,b,a,poz,pozm,lm,l,v[400002];
long long smax,best[400002];
int main()
{
fin>>n;
for(i=1; i<=n; i++)
{
fin>>a>>b;
if(b==0)
{
v[i]=v[n+i]=-a;
}
else v[i]=v[n+i]=a;
}
smax=v[1];
n=2*n;
poz=1;
l=1;
for(i=1; i<=n; i++)
{
best[i]=v[i];
if(best[i]<best[i-1]+v[i])
{
if(l<n/2)best[i]=best[i-1]+v[i],l++;
else best[i]=v[i];
}
else
{
poz=i;
l=1;
}
if(smax<best[i]&&l<n) smax=best[i],pozm=poz,lm=l;
}
if(pozm<n/2) fout<<smax<<" "<<pozm<<" "<<lm;
else fout<<smax<<" "<<n-pozm<<" "<<lm;
return 0;
}