Problem:
問題文
実数変数 $x_1, x_2, ..., x_N$ は以下の条件を満たす。
$0 \leq x_i \leq 1$ ($1 \leq i \leq N$)
$w_1x_1+w_2x_2+...+w_Nx_N \leq W$
このとき $v_1x_1+v_2x_2+...+v_Nx_N$ のとりうる最大値を求めよ。そのような最大値は実際に存在することが知られている。
入力
入力は以下の形式に従う。与えられる数は全て整数である。
$N$ $W$
$w_1$ $v_1$
$w_2$ $v_2$
$...$
$w_N$ $v_N$
制約
$1 \leq N \leq 10^5$
$1 \leq W \leq 10^5$
$-10^4 \leq w_i \leq 10^4$
$-10^4 \leq v_i \leq 10^4$
出力
$v_1x_1+v_2x_2+...+v_Nx_N$ のとりうる最大値を1行に出力せよ。
出力には $10^{-3}$ を超える誤差があってはならない。
Sample Input 1
1 1
3 1
Output for the Sample Input 1
0.333333
$x_1=1/3$ のとき最大となる。
Sample Input 2
2 3
3 3
1 2
Output for the Sample Input 2
4.000000
Sample Input 3
2 1
-1 -3
3 10
Output for the Sample Input 3
3.666667

Submitted solutions:

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#include<random>
#pragma warning(disable:4996)
using namespace std;
using ld= long double;

int main()
{
	int N;
	ld W;
	cin>>N>>W;
	vector<pair<ld,ld>>pluss;
	ld ans=0;
	for (int i = 0; i < N; ++i) {
		ld w,v;cin>>w>>v;
		if (w > 0) {
			if (v > 0) {
				pluss.emplace_back(w, v);
			}
			else if (v <= 0) {

			}
		}
		else {
			if (v >= 0) {
				ans += v;
				W -= w;
			}
			else {
				if (w < 0) {
					ans+=v;
					W-=w;
					pluss.emplace_back(-w,-v);
				}
			}
		}
	}
	sort(pluss.begin(), pluss.end(), [](const pair<ld, ld>&l, const pair<ld, ld>&r) {
		return l.second/l.first>r.second/r.first;
	});

	ld rest(W);
	int now(0);
	while (rest > 0&&now!=pluss.size()) {
		ld use=min(pluss[now].first,rest);
		ans+=use/pluss[now].first*pluss[now].second;
		rest-=use;
		now++;
	}
	cout<<setprecision(10)<<fixed<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3404
final_rank: 12

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<tuple>
using namespace std;
long double w[100000], v[100000], W; int n;
vector<tuple<long double, long double, long double>>p1, p2;
long double solve(vector<tuple<long double, long double, long double>>x, long double t, int q) {
	long double vl = 0;
	for (int i = x.size() - 1; i >= 0; i--) {
		if (q == 0 && get<0>(x[i]) < 0)break;
		if (t >= get<2>(x[i])) { t -= get<2>(x[i]); vl += get<1>(x[i]); }
		else { vl += get<1>(x[i])*t / get<2>(x[i]); t = 0; }
	}
	return vl;
}
int main() {
	cin >> n >> W; long double r = 0, f = 0, e = 0;
	for (int i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
		if (fabs(w[i]) < 1e-14) { r += max(0.0l, v[i]); }
		else if (w[i] > 0) { p1.push_back(make_tuple(v[i] / w[i], v[i], w[i])); }
		else if (w[i] < 0) { p2.push_back(make_tuple(-v[i] / w[i], v[i], -w[i])); e += -w[i]; }
	}
	sort(p1.begin(), p1.end()); sort(p2.begin(), p2.end());
	long double L = 0, R = e, c1, c2;
	for (int i = 0; i < 100; i++) {
		c1 = (L + L + R) / 3.0l; c2 = (L + R + R) / 3.0l;
		long double ret1 = solve(p1, c1 + W, 0) + solve(p2, c1, 1);
		long double ret2 = solve(p1, c2 + W, 0) + solve(p2, c2, 1);
		if (ret1 >= ret2)R = c2;
		else L = c1;
		f = max(f, max(ret1, ret2));
	}
	printf("%.12Lf\n", r + f);
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4376
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

bool comp(const pii &a, const pii &b){
  return b.first*a.second > a.first*b.second;
}

int main(){
  int n,w;
  cin >> n >> w;
  double res = 0;

  vector<pii> item;
  for(int i=0;i<n;i++){
    int a,b;
    cin >> a >> b;
    if(a<=0 && b>=0)w+=-a, res+=b;
    else if(a<0 && b<0){
      w+=-a, res+=b;
      item.push_back(pii(-a,-b));
    }else if(a>0 && b>0){
      item.push_back(pii(a,b));
    }      
  }
  
  sort(item.begin(),item.end(),comp);

  for(pii p : item){
    if(w>p.first){
      w -= p.first; res += p.second;
    }else{
      res += (double)w/p.first * p.second;
      break;
    }
  }
  cout << fixed << setprecision(9) << res << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 1368
final_rank: 9

code_snippet: #include<iostream>
#include<vector>
#include<tuple>
#include<algorithm>

using namespace std;

int main(){
  int N,W;
  cin>>N>>W;
  double cw=0,cv=0;
  vector<tuple<double,double,double> > p,n;
  while(N--){
    long long w,v;
    cin>>w>>v;
    if(w*v>0){
      ((w>0)?p:n).emplace_back(v*1./w,1.*w,1.);
    }else if(v>=0&&w<=0){
      cw+=w;
      cv+=v;
    }
  }
  sort(begin(p),end(p));
  sort(n.rbegin(),n.rend());
  while(!p.empty()){
    double vw=get<0>(p.back());
    double w=get<1>(p.back());
    double &r=get<2>(p.back());
    if(cw+w*r<=W){
      cw+=w*r;
      cv+=vw*w*r;
      p.pop_back();
    }else{
      double l=(W-cw)/w;
      cv+=vw*w*l;
      r-=l;
      break;
    }
  }
  double m=cv;
  while(!p.empty()&&!n.empty()){
    auto &pb=p.back();
    auto &nb=n.back();
    double l=min(get<2>(pb)*get<1>(pb),-get<2>(nb)*get<1>(nb));
    cv+=(get<0>(pb)-get<0>(nb))*l;
    m=max(m,cv);
    get<2>(pb)-=l/get<1>(pb);
    get<2>(nb)-=l/-get<1>(nb);
    ((get<2>(nb)<get<2>(pb))?n:p).pop_back();
  }
  cout<<fixed<<m<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 1544
final_rank: 11

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;

const int MAXN = 100005;

int N;
double W;
double w[MAXN], v[MAXN];

double V;
vector<pair<double,double> > A;

bool comp(const pair<double,double> &a, const pair<double,double> &b) {
  return a.second*b.first > b.second*a.first;
}

int main() {
  cin >> N >> W;
  for(int i = 0; i < N; ++i) {
    cin >> w[i] >> v[i];
  }

  V = 0;

  A.clear();
  for(int i = 0; i < N; ++i) {
    if(w[i] >= 0 && v[i] <= 0) {
      //
    } else if(w[i] <= 0 && v[i] >= 0) {
      W -= w[i];
      V += v[i];
    } else if(w[i] >= 0 && v[i] >= 0) {
      A.push_back(make_pair(w[i],v[i]));
    } else {
      W -= w[i];
      V += v[i];
      A.push_back(make_pair(-w[i],-v[i]));
    }
  }

  sort(A.begin(), A.end(), comp);
  for(int i = 0; i < A.size(); ++i) {
    double x = min(1.0, W/A[i].first);
    W -= A[i].first*x;
    V += A[i].second*x;
  }
  printf("%.6f\n", V);
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1536
final_rank: 10

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>

#define EPS 1e-9

using namespace std;

int n;
double W;

bool pred(pair<int,int> a, pair<int,int> b){
    return a.first * b.second > a.second * b.first;
}

int main(){
    cin >> n >> W;
    vector<pair<int,int> > vp;
    double ret=0;
    double w,v;
    for(int i=0;i<n;i++){
        cin >> w >> v;
        if(w <= 0 && v >= 0){
            W -= w;
            ret += v;
        }else if(w >=0 && v <= 0){
            //do nothing
        }else if(v < 0 && w < 0){
            W -= w;
            ret += v;
            vp.push_back(make_pair(-v,-w));
        }else{
            vp.push_back(make_pair(v,w));
        }
    }
    sort(vp.begin(), vp.end(), pred);
    for(int i=0;i<vp.size();i++){
        double tmp = min(1.0, W/vp[i].second);
        ret += vp[i].first * tmp;
        W -= tmp * vp[i].second;
        if(W < EPS) break;
    }
    printf("%.9f\n", ret);
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include<iostream>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

struct st{
  double v,w;
  bool operator<(const st & a)const{
    return v/w < a.v/a.w;
  }
  bool operator>(const st & a)const{
    return v/w > a.v/a.w;
  }
};

double solve(double w,vector<st> & pos,vector<st> & neg){
  double posx=0;/*ppが指しているものweight*/
  double negx=1;
  double ret = 0;
  int pp = 0,np = 0;
  while(pp < pos.size() && w > 0){
    double tx = min(1.0,w/pos[pp].w);
    ret += pos[pp].v * tx;
    w -= tx * pos[pp].w;
    if (w < 1e-10){
      posx = 1-tx;
      break;
    }
    else pp++;
  }
  if (posx < 1e-10)pp++,posx = 1;
  //cout << "pp : " << ret <<" "<< posx << endl;

  while(pp < pos.size() && np < neg.size()){
    /*posxを詰め込むために必要なw。*/
    double pw = posx * pos[pp].w;
    /*negxによって、開けることができるw。*/
    double gw = negx * -neg[np].w;
    double used = min(pw,gw);
    double px = used/pos[pp].w;
    double gx = used/-neg[np].w;
    if (px * pos[pp].v < gx * -neg[np].v)break;/*これ以上は、負/負のものを使っても価値が増えることはない。*/
    ret += px * pos[pp].v;
    ret += gx * neg[np].v;

    posx -= px;
    negx -= gx;

    if (posx < 1e-10)pp++,posx = 1;
    if (negx < 1e-10)np++,negx = 1;
  }
  return ret;
}

main(){
  int n,w;
  while(cin>>n>>w && n){
    double ans=0,wlim = w;
    vector<st> pos,neg;
    rep(i,n){
      double tw,tv;
      cin>>tw>>tv;
      if (tw <= 0 && tv >= 0){//全部使って良い
	w -= tw;
	ans += tv;
      }else if (0 < tw && tv <= 0){//一つも使わない。
      }else if (tw >= 0 && tv > 0){//
	pos.push_back((st){tv,tw});
      }else if (tw < 0 && tv <= 0){
	neg.push_back((st){tv,tw});
      }
    }
    sort(pos.begin(),pos.end(),greater<st>());
    sort(neg.begin(),neg.end());
    //rep(i,pos.size())cout << pos[i].w <<" " << pos[i].v << endl;
    double tmp = solve(w,pos,neg);
    printf("%.10lf\n",tmp+ans);
  }
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0; i<(int)n; ++i)

int main() {
    int n,W;
    cin>>n>>W;

    double ans = 0,weight = 0.0;
    vector<double> w(n), v(n);
    rep(i,n) cin>>w[i]>>v[i];

    vector<pair<double,int> > pv;
    rep(i,n) {
        if(w[i] >= 0 && v[i] <= 0) continue;
        if(w[i] <= 0 && v[i] >= 0) {
            ans += v[i], weight += w[i];
            continue;
        }

        if(v[i] >= 0) {
            ans += v[i], weight += w[i];
            w[i] *= -1, v[i] *= -1;
        }
        pv.push_back(make_pair(v[i]/w[i],i));
    }

    sort(pv.begin(), pv.end());
    //reverse(pv.begin(), pv.end());

    rep(i,pv.size()) {
        if(weight <= W) break;
        int idx = pv[i].second;

        if(weight+w[idx] >= W) {
            weight += w[idx];
            ans += v[idx];
        }else{
            ans += v[idx]*(W-weight)/w[idx];
            weight = W;
        }
    }

    printf("%.12f\n", ans);
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

const double EPS=(1e-10);
typedef long long ll;
bool EQ(double a,double b){
  return abs((a)-(b))<EPS;
}
int N;
double W;
double wi[100001];
double vi[100001];
double xi[100001];

typedef pair<double,int> pdi;

void solve(){
    cin>>N>>W;
    for(int i=0;i<N;i++)cin>>wi[i]>>vi[i];
    for(int i=0;i<N;i++)xi[i]=1;
    priority_queue<pdi> grt;
    priority_queue<pdi> dec;
    double maxVal=0;
    for(int i=0;i<N;i++){
        if((wi[i]<0||EQ(wi[i],0))&&(vi[i]>0||EQ(vi[i],0))){
            xi[i]=0;
            maxVal+=vi[i];
            W+=(-wi[i]);
        }
        else if((wi[i]>0||EQ(wi[i],0))&&(vi[i]<0||EQ(vi[i],0)))xi[i]=0;
        else{
            if(wi[i]<0&&vi[i]<0){
                wi[i]*=-1;
                vi[i]*=-1;
                dec.push(pdi(wi[i]/vi[i],i));
            }
            else if(wi[i]>0&&vi[i]>0)grt.push(pdi(vi[i]/wi[i],i));
        }
    }
    while(grt.size()){
        pdi p=grt.top();grt.pop();
        if(wi[p.second]*xi[p.second]<W||EQ(wi[p.second]*xi[p.second],W)){
            W-=wi[p.second]*xi[p.second];
            maxVal+=vi[p.second]*xi[p.second];
            xi[p.second]=0;
        }
        else{
            double quan=W/(wi[p.second]);
            if(!EQ(quan,0)){
                maxVal+=vi[p.second]*quan;
                xi[p.second]-=quan;;
                grt.push(p);
                W=0;
            }
            else{
                double needW=xi[p.second]*wi[p.second];
                double curFullVal=xi[p.second]*vi[p.second];
                double curGetW=0;
                double curGetVal=0;
                while(dec.size()){
                    pdi pp=dec.top();dec.pop();
                    if(!EQ(p.first,(1.0/pp.first))&&(p.first<1.0/pp.first))break;
                    if(EQ(curGetW+wi[pp.second]*xi[pp.second],needW)||curGetW+wi[pp.second]*xi[pp.second]>needW){
                        double curQuan=(needW-curGetW)/wi[pp.second];
                        curGetW+=curQuan*wi[pp.second];
                        curGetVal+=curQuan*vi[pp.second];
                        xi[pp.second]-=curQuan;
                        if(!EQ(1,xi[pp.second]))dec.push(pp);
                        break;
                    }
                    else{
                        curGetW+=wi[pp.second]*xi[pp.second];
                        curGetVal+=vi[pp.second]*xi[pp.second];
                    }
                }
                if(EQ(curGetW,needW)){
                    if(EQ(curGetVal,curFullVal)||curGetVal<curFullVal)maxVal+=curFullVal-curGetVal;
                    else break;
                }
                else{
                    if(curGetVal<curFullVal*(curGetW/needW)||EQ(curGetVal,curFullVal*(curGetW/needW)))
                        maxVal+=(-curGetVal+curFullVal*(curGetW/needW));
                    break;
                }
            }
        }
    }
    printf("%.10f\n",maxVal);
}
int main(){
    solve();

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>


using namespace std;

const double EPS=(1e-10);
typedef long long ll;
typedef pair<int,int> pii;
bool EQ(double a,double b){
  return abs((a)-(b))<EPS;
}
void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}
int N;
double W;
double wi[100001];
double vi[100001];
double xi[100001];

typedef pair<double,int> pdi;

void solve(){
    cin>>N>>W;
    for(int i=0;i<N;i++)cin>>wi[i]>>vi[i];
    for(int i=0;i<N;i++)xi[i]=1;
    priority_queue<pdi> grt;
    priority_queue<pdi> dec;
    double maxVal=0;
    for(int i=0;i<N;i++){
        if((wi[i]<0||EQ(wi[i],0))&&(vi[i]>0||EQ(vi[i],0))){
            xi[i]=0;
            maxVal+=vi[i];
            W+=(-wi[i]);
        }
        else if((wi[i]>0||EQ(wi[i],0))&&(vi[i]<0||EQ(vi[i],0)))xi[i]=0;
        else{
            if(wi[i]<0&&vi[i]<0){
                wi[i]*=-1;
                vi[i]*=-1;
                dec.push(pdi(wi[i]/vi[i],i));
            }
            else if(wi[i]>0&&vi[i]>0)grt.push(pdi(vi[i]/wi[i],i));
        }
    }
    while(grt.size()){
        pdi p=grt.top();grt.pop();
        if(wi[p.second]*xi[p.second]<W||EQ(wi[p.second]*xi[p.second],W)){
            W-=wi[p.second]*xi[p.second];
            maxVal+=vi[p.second]*xi[p.second];
            xi[p.second]=0;
        }
        else{
            double quan=W/(wi[p.second]);
            if(!EQ(quan,0)){
                maxVal+=vi[p.second]*quan;
                xi[p.second]-=quan;;
                grt.push(p);
                W=0;
            }
            else{
                double needW=xi[p.second]*wi[p.second];
                double curFullVal=xi[p.second]*vi[p.second];
                double curGetW=0;
                double curGetVal=0;
                while(dec.size()){
                    pdi pp=dec.top();dec.pop();
                    if(!EQ(p.first,(1.0/pp.first))&&(p.first<1.0/pp.first)){
                        break;
                    }
                    if(EQ(curGetW+wi[pp.second]*xi[pp.second],needW)||curGetW+wi[pp.second]*xi[pp.second]>needW){
                        double curQuan=(needW-curGetW)/wi[pp.second];
                        curGetW+=curQuan*wi[pp.second];
                        curGetVal+=curQuan*vi[pp.second];
                        xi[pp.second]-=curQuan;
                        if(!EQ(1,xi[pp.second]))dec.push(pp);
                        break;
                    }
                    else{
                        curGetW+=wi[pp.second]*xi[pp.second];
                        curGetVal+=vi[pp.second]*xi[pp.second];
                    }
                }
                if(EQ(curGetW,needW)){
                    if(EQ(curGetVal,curFullVal)||curGetVal<curFullVal)maxVal+=curFullVal-curGetVal;
                    else break;
                }
                else{
                    if(curGetVal<curFullVal*(curGetW/needW)||EQ(curGetVal,curFullVal*(curGetW/needW)))
                        maxVal+=(-curGetVal+curFullVal*(curGetW/needW));
                    break;
                }
            }
        }
    }
    printf("%.10f\n",maxVal);
}

int main(){
    solve();

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>


using namespace std;

const double EPS=(1e-10);
typedef long long ll;
typedef pair<int,int> pii;
bool EQ(double a,double b){
  return abs((a)-(b))<EPS;
}
void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}
int N;
double W;
double wi[100001];
double vi[100001];
double xi[100001];

typedef pair<double,int> pdi;

void solve(){
    cin>>N>>W;
    for(int i=0;i<N;i++)cin>>wi[i]>>vi[i];
    for(int i=0;i<N;i++)xi[i]=1;
    priority_queue<pdi> grt;
    priority_queue<pdi> dec;
    double maxVal=0;
    for(int i=0;i<N;i++){
        if((wi[i]<0||EQ(wi[i],0))&&(vi[i]>0||EQ(vi[i],0))){
            xi[i]=0;
            maxVal+=vi[i];
            W+=(-wi[i]);
        }
        else if((wi[i]>0||EQ(wi[i],0))&&(vi[i]<0||EQ(vi[i],0)))xi[i]=0;
        else{
            if(wi[i]<0&&vi[i]<0){
                wi[i]*=-1;
                vi[i]*=-1;
                dec.push(pdi(wi[i]/vi[i],i));
            }
            else if(wi[i]>0&&vi[i]>0)grt.push(pdi(vi[i]/wi[i],i));
        }
    }
    while(grt.size()){
        pdi p=grt.top();grt.pop();
        if(wi[p.second]*xi[p.second]<W||EQ(wi[p.second]*xi[p.second],W)){
            W-=wi[p.second]*xi[p.second];
            maxVal+=vi[p.second]*xi[p.second];
            xi[p.second]=0;
        }
        else{
            double quan=W/(wi[p.second]);
            if(!EQ(quan,0)){
                maxVal+=vi[p.second]*quan;
                xi[p.second]-=quan;;
                grt.push(p);
                W=0;
            }
            else{
                double needW=xi[p.second]*wi[p.second];
                double curFullVal=xi[p.second]*vi[p.second];
                double curGetW=0;
                double curGetVal=0;
                while(dec.size()){
                    pdi pp=dec.top();dec.pop();
                    if(!EQ(p.first,(1.0/pp.first))&&(p.first<1.0/pp.first)){
                        break;
                    }
                    if(EQ(curGetW+wi[pp.second]*xi[pp.second],needW)){
                        curGetW+=xi[pp.second]*wi[pp.second];
                        curGetVal+=xi[pp.second]*vi[pp.second];
                        xi[pp.second]=0;
                        break;
                    }
                    else if(curGetW+wi[pp.second]*xi[pp.second]>needW){
                        double curQuan=(needW-curGetW)/wi[pp.second];
                        curGetVal+=curQuan*vi[pp.second];
                        curGetW+=curQuan*wi[pp.second];
                        xi[pp.second]-=curQuan;
                        dec.push(pp);
                        break;
                    }
                    else{
                        curGetW+=wi[pp.second]*xi[pp.second];
                        curGetVal+=vi[pp.second]*xi[pp.second];
                    }
                }
                if(EQ(curGetW,needW)){
                    if(EQ(curGetVal,curFullVal)||curGetVal<curFullVal)maxVal+=curFullVal-curGetVal;
                    else break;
                }
                else{
                    if(curGetVal<curFullVal*(curGetW/needW)||EQ(curGetVal,curFullVal*(curGetW/needW)))
                        maxVal+=(-curGetVal+curFullVal*(curGetW/needW));
                    break;
                }
            }
        }
    }
    printf("%.10f\n",maxVal);
}
int main(){
    solve();

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>

using namespace std;

const double EPS=(1e-10);
typedef long long ll;
typedef pair<int,int> pii;
bool EQ(double a,double b){
  return abs((a)-(b))<EPS;
}
void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}
int N;
double W;
double wi[100001];
double vi[100001];
double xi[100001];

typedef pair<double,int> pdi;

void solve(){
    cin>>N>>W;
    for(int i=0;i<N;i++)cin>>wi[i]>>vi[i];
    for(int i=0;i<N;i++)xi[i]=1;
    priority_queue<pdi> grt;
    priority_queue<pdi> dec;
    double maxVal=0;
    for(int i=0;i<N;i++){
        // w<0,v>0
        if((wi[i]<0||EQ(wi[i],0))&&(vi[i]>0||EQ(vi[i],0))){
            xi[i]=0;
            maxVal+=vi[i];
            W+=(-wi[i]);
        }
        else if((wi[i]>0||EQ(wi[i],0))&&(vi[i]<0||EQ(vi[i],0)))xi[i]=0;
        else{
            // RXgà¿là¸ç·âÂÍA¦ª¢ÔÉqueueÉËÁñÅ¨­
            if(wi[i]<0&&vi[i]<0){
                wi[i]*=-1;
                vi[i]*=-1;
                dec.push(pdi(wi[i]/vi[i],i));
            }
            else if(wi[i]>0&&vi[i]>0)grt.push(pdi(vi[i]/wi[i],i));
        }
    }
    while(grt.size()){
        pdi p=grt.top();grt.pop();
        // ®SÉæ¾Â\Å êÎASÄæ¾
        if(wi[p.second]*xi[p.second]<W||EQ(wi[p.second]*xi[p.second],W)){
            W-=wi[p.second]*xi[p.second];
            maxVal+=vi[p.second]*xi[p.second];
            xi[p.second]=0;
        }
        else{
            // SÄæ¾Å«È¢ê,Ü¸æêé¾¯æé
            double quan=W/(wi[p.second]);
            if(!EQ(quan,0)){
                // quanÌª¾¯æé
                maxVal+=vi[p.second]*quan;
                xi[p.second]-=quan;;
                grt.push(p);
                W=0;
            }
            else{
                // cèSÄðèÄéÌÉKvÈWÌÊ
                double needW=xi[p.second]*wi[p.second];
                double curFullVal=xi[p.second]*vi[p.second];
                double curGetW=0;
                double curGetVal=0;
                // decÍ¿lðâ¹È­ÈÁ½çà¤æéÌðâßé
                while(dec.size()){
                    pdi pp=dec.top();dec.pop();
                    // àµ»Ý
                    if(!EQ(p.first,(1.0/pp.first))&&(p.first<1.0/pp.first)){
                        break;
                    }
                    // ¡ñÌ}CiXªÅAd³SÄðÜ©È¦éæ¤ÉÈÁ½çÎAI¹
                    if(EQ(curGetW+wi[pp.second]*xi[pp.second],needW)){
                        // ¡ñèÉüêçê½d³
                        curGetW+=xi[pp.second]*wi[pp.second];
                        // ¿lð¡ñÌª¾¯ÁZ
                        curGetVal+=xi[pp.second]*vi[pp.second];
                        xi[pp.second]=0;
                        break;
                    }
                    else if(curGetW+wi[pp.second]*xi[pp.second]>needW){
                        // KvÈÊ¾¯èÉüêé
                        double curQuan=(needW-curGetW)/wi[pp.second];
                        curGetVal+=curQuan*vi[pp.second];
                        curGetW+=curQuan*wi[pp.second];
                        xi[pp.second]-=curQuan;
                        dec.push(pp);
                        break;
                    }
                    else{
                        // Ü¾needWæè­È¢öxÌÊµ©È¢
                        curGetW+=wi[pp.second]*xi[pp.second];
                        curGetVal+=vi[pp.second]*xi[pp.second];
                    }
                }
                if(EQ(curGetW,needW)){
                    // ðð½¹È¢ÈçÎA»êÈãæÁÄà³ÊÈÌÅAI¹
                    if(EQ(curGetVal,curFullVal)||curGetVal<curFullVal)maxVal+=curFullVal-curGetVal;
                    else break;
                }
                // ÅãÜÅæêÈ©Á½êARÜÅÆÁ½ªÅl¦é
                else{
                    if(curGetVal<curFullVal*(curGetW/needW)||EQ(curGetVal,curFullVal*(curGetW/needW)))
                        maxVal+=(-curGetVal+curFullVal*(curGetW/needW));
                    break;
                }
            }
        }
    }
    printf("%.10f\n",maxVal);
}

int main(){
    solve();

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);

double w[100000];
double v[100000];
typedef pair<double,int> pdi;
double a[100000];
const double EPS = 1e-8;

int main() {
  int N;
  double W;
  cin >> N >> W;  
  
  vector<pdi> vec1, vec2;
  double ans = 0;
  REP(i, N) {
    cin >> w[i] >> v[i];
    if (w[i]>0 && v[i]>0) {
      vec1.push_back(pdi((double)v[i]/w[i], i));
    } else if (w[i]<0 && v[i]<0) {
      w[i] = abs(w[i]);
      v[i] = abs(v[i]);
      vec2.push_back(pdi((double)v[i]/w[i], i));
    } else if (w[i]>0 && v[i]<=0) {
    } else if (w[i]<=0 && v[i]>=0) { 
      ans += v[i];
      W += abs(w[i]);
    }
  }
  sort(ALL(vec1), greater<pdi>());
  sort(ALL(vec2));
  memset(a,0,sizeof(a));
  int j = 0;
  for (int i=0; i<vec1.size(); ++i) {
    int idx = vec1[i].second;
    if (w[idx]<=W) {		// 1 wariate
      ans += v[idx];
      W -= w[idx];
    } else {
      ans += v[idx] * W/w[idx];
      a[idx] = W/w[idx];
      W = 0;
      while(a[idx] < 1) {
      //while(w[idx]>W+EPS) {
	if (j >= vec2.size() || vec2[j].first >= vec1[i].first) {
	  break;
	}
	int jdx = vec2[j].second;
	double hoge = min(w[idx]*(1-a[idx])/w[jdx], 1-a[jdx]);
	a[jdx] += hoge;
	double hoge2 = (w[jdx]*hoge)/w[idx];
	//cout << "hoge = " << hoge << endl;
	//cout << "hoge2 = " << hoge2 << endl;
	a[idx] += hoge2;
	ans += v[idx] * hoge2;
	//cout << "ans1 = " << ans  << endl;
	ans -= v[jdx] * hoge;
	//cout << "ans2 = " << ans << endl;
	if (a[jdx] > 1-EPS) j++;
      }
      //cout << "!!" << 1-a[idx] << endl;
    }
    //cout << W << ":  " << ans << endl;
  }
  printf("%.10f\n", ans);
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1