Pagini recente » Cod sursa (job #509749) | Cod sursa (job #232839) | Cod sursa (job #1940580) | Cod sursa (job #664754) | Cod sursa (job #1979972)
#include<fstream>
using namespace std;
ifstream in("buline.in");
ofstream out("buline.out");
int v[200001],d[200001];
int lmax,lmin,maxim,minim,pozmin,pozmax,l,ok,n,i,x,poz;
long long s;
int main(){
in >> n;
for( i = 1; i <= n; i ++ ){
in >> v[i] >> x;
if( x == 0 ){
v[i]*=-1;
}
s+=v[i];
}
for( i = 1; i <= n; i ++ ){
if( d[i-1] <= 0 || i == 1 ){
d[i] = v[i];
l = 1;
poz = i;
}
else{
d[i]=d[i-1]+v[i];
l++;
}
if( ok == 0 ){
maxim = d[i];
pozmax = poz;
lmax = l;
ok = 1;
}
if( maxim < d[i] ){
maxim = d[i];
pozmax = poz;
lmax = l;
}
}
ok = 0;
for( i = 1; i <= n; i ++ ){
if( d[i-1] >= 0 || i == 1 ){
d[i] = v[i];
l = 1;
}
else{
d[i] = d[i-1] + v[i];
l ++;
}
if( ok == 0 ){
minim = d[i];
pozmin = i;
lmin = l;
ok = 1;
}
if( minim > d[i] ){
minim = d[i];
pozmin = i;
lmin = l;
}
}
if( maxim > (s-minim) ){
out << maxim <<" "<<pozmax<<" "<<lmax;
}
else{
out <<s-minim <<" "<<pozmin + 1 <<" "<<n - lmin ;
}
return 0;
}