Pagini recente » Cod sursa (job #1037671) | Cod sursa (job #2701853) | Cod sursa (job #1882184) | Cod sursa (job #1996814) | Cod sursa (job #259847)
Cod sursa(job #259847)
#include<fstream.h>
#include<values.h>
ifstream f("buline.in");
ofstream g("buline.out");
int x,y,a[2]={-1,1},n,i,j,v[400001],p,l;
long max,z[400001];
int main(){
f>>n;
for(i=1;i<=n;i++){
f>>x>>y;
v[i]=x*a[y];
v[n+i]=x*a[y];
z[i]=z[i-1]+v[i];}
max=-MAXLONG;
for(i=1;i<=n;i++)
for(j=i+1;j<=n+i-1;j++){
if(i==1&&j<=n)
z[j+n-1]=z[j+n-2]+v[j-1];
if((z[j]-z[i-1])>max){
max=z[j]-z[i-1];
p=i;l=j-i+1;}
else if(z[j]-z[i-1]==max)
if(i==p&&(j-i+1)<l)
l=j-l+1;}
g<<max<<" "<<p<<" "<<l;
return 0;
}