/*In Case of TLE -> 1.Use Int instead of Long Long
                    2.Use FastIO
                    3.Use "\n" Instead of endl
                    4.Use Vector and Arrays instead of Sets,Maps(if possible)
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 10000003  //N idhar hai
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) >= (b); --(i))
#define rep(i, c) for(auto &(i) : (c))
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define getsm(v) accumulate(all(v),(ll)0)
#define getmx(v) max_element(all(v))
#define getmn(v) min_element(all(v))
#define wr1(a) cout<<(a)<<endl
#define wr2(a,b) cout<<(a)<<" "<<(b)<<endl
#define wr3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define ww1(a) cout<<(a)<<"\n"
#define ww2(a,b) cout<<(a)<<" "<<(b)<<"\n"
#define ww3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define call(dr) dr.pb(mkp(1,0));dr.pb(mkp(-1,0));dr.pb(mkp(0,1));dr.pb(mkp(0,-1))
#define fill(dp,a,b) for(int i=0;i<a;i++)for(int j=0;j<b;j++)dp[i][j]=-1;
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define bitcount( x ) __builtin_popcountll( x )
#define ls(i) (1ll<<(i))
#define rs(i) ((i)>>1)
#define br "\n"
//#define sp " "
using namespace __gnu_pbds; //required
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
double power(double k , long long n ){double res = 1;while(n){if(n%2!=0){res = (res*k) ;}k = (k*k) ;n = n/2 ;}return(res) ;}
ll sign(ll i){if(i==0){return(0);}if(i>0){return(1);}return(-1);}
double distance(pll a , pll b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se-b.se))));}
double distance(pair<ll,pll> a , pair<ll,pll> b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se.fi-b.se.fi) + sqr(a.se.se - b.se.se))));}
//ll lis(vll v){ll d = sz(v);vll dis(d+1,inf);for(ll i = 0 ; i<d ; i++){*lowerB(all(dis),v[i]) = v[i];}for(ll i=0 ; i<d+1 ; i++){if(dis[i]==inf){return(i);}}return(1);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }//for strictly increasing use lower bound(in function lis) otherwhise use upper bound
#define lcm(a,b) ((a/gcd(a,b))*b)
const ll dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const ll dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vpll dr;
ll n,m,k,h,a1,a2,t;
db prob;
string str;
bool ok = true;
vpll v;
void check(db q , ll b)
{
    ll c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    //temp is too high
    //p is for low
    //q is for high
    //a is for low
    //b is for high
    for(i=n-1 ; i>=0 ; i--)
    {
        c = v[i].fi;
        d = v[i].se;
        db r = (q-c*d)/(db)(b-d);
        if(r>t)
        {
            b-=d;
            q-=c*d;
        }
        else
        {
            b-=d;
            q-=c*d;
            break;
        }
    }
    //c is temp and d is maximum value of water having temp c
    db lo = 0;
    db hi = d;
    z = 0;
    while(z<N)
    {
        z++;
        db mid = lo + (hi-lo)/2;
        db temp = (q+mid*c)/(db)(b+mid);
        if(temp>=t)
        {
            hi = mid;
        }
        else
        {
            lo = mid;
        }
    }
    showzero;
    ww1(b+hi);
}
int main()
{
    FastIO;
    PRECISION(15);
    ll a,b,c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    db p,q,r,w;
    char ch,chr ;
    string str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //Listen to Zero(Imagine Dragons!!)
    //Listen to Burn(Ellie Goulding)
    //Stay Motivated!!
    //Never use i for two or more nested loops!!
    //Range Query + Constructive + DSU +  Graph Theory + Math + Number Theory + DP(DP + DP with Bitmasks + DP on Trees) + Bitmasks + Data Structures + Strings + Geometry
    //Binary and Ternary Search + Brute Force + Greedy + Implementation
    //In a comparator function comp(pll a , pll b) if comp returns true then a comes before b otherwise b comes berfore a
    //For Longest Common Palindromic Subsequence find the Longest Common subsequence between Original Array and Reverse of the original array
    //Fuck Excuses!!Focus on how to get better
    //First Think then code
    //memset(viv,false,sof(viv));
    //memset(dp,-1,sof(dp));
    //call(dr);
    //1920
    //ThinkThinkThinkThink NOW
    cin>>n>>t;
    v.resz(n);
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].se = a;
    }
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].fi = a;
    }
    sort(all(v));
    a = 0; //total volume of water with temp less than T
    p = 0; //total temp with water having temp less than T
    b = 0;//total volume of water with temp more than T
    q = 0;//total temp with water having temp more than T
    for(i=0 ; i<n ; i++)
    {
        if(v[i].fi>=t)
        {
            b+=v[i].se;
            q+=(v[i].se*v[i].fi);
        }
        else
        {
            a+=v[i].se;
            p+=(v[i].se*v[i].fi);
        }
    }
    if(v[n-1].fi<t)
    {
        ww1(-1);
        exit(0);
    }
    r = (p+q)/(db)(a+b);
    if(r<t)
    {
        t = -t;
        for(i=0 ; i<n; i++)
        {
            v[i].fi = -v[i].fi;
        }
        sort(all(v));
        p = -p;
        q = -q;
    }
    q+=p;
    b+=a;
    check(q,b);
}
//Always Check for Binary Search(Along with Lower/Upper Bound) , Ternary Search , Greedy then go for DP , DFS , DSU  + Bridge Tree + and other stuff(described above)
//DO IT UNTIL YOU RUN OUT OF IDEAS ~ YOU KNOW WHO
//See The Editorial AN ~ YOU KNOW WHO


/*In Case of TLE -> 1.Use Int instead of Long Long
                    2.Use FastIO
                    3.Use "\n" Instead of endl
                    4.Use Vector and Arrays instead of Sets,Maps(if possible)
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 1000003  //N idhar hai
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) >= (b); --(i))
#define rep(i, c) for(auto &(i) : (c))
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define getsm(v) accumulate(all(v),(ll)0)
#define getmx(v) max_element(all(v))
#define getmn(v) min_element(all(v))
#define wr1(a) cout<<(a)<<endl
#define wr2(a,b) cout<<(a)<<" "<<(b)<<endl
#define wr3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define ww1(a) cout<<(a)<<"\n"
#define ww2(a,b) cout<<(a)<<" "<<(b)<<"\n"
#define ww3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define call(dr) dr.pb(mkp(1,0));dr.pb(mkp(-1,0));dr.pb(mkp(0,1));dr.pb(mkp(0,-1))
#define fill(dp,a,b) for(int i=0;i<a;i++)for(int j=0;j<b;j++)dp[i][j]=-1;
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define bitcount( x ) __builtin_popcountll( x )
#define ls(i) (1ll<<(i))
#define rs(i) ((i)>>1)
#define br "\n"
//#define sp " "
using namespace __gnu_pbds; //required
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
double power(double k , long long n ){double res = 1;while(n){if(n%2!=0){res = (res*k) ;}k = (k*k) ;n = n/2 ;}return(res) ;}
ll sign(ll i){if(i==0){return(0);}if(i>0){return(1);}return(-1);}
double distance(pll a , pll b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se-b.se))));}
double distance(pair<ll,pll> a , pair<ll,pll> b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se.fi-b.se.fi) + sqr(a.se.se - b.se.se))));}
//ll lis(vll v){ll d = sz(v);vll dis(d+1,inf);for(ll i = 0 ; i<d ; i++){*lowerB(all(dis),v[i]) = v[i];}for(ll i=0 ; i<d+1 ; i++){if(dis[i]==inf){return(i);}}return(1);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }//for strictly increasing use lower bound(in function lis) otherwhise use upper bound
#define lcm(a,b) ((a/gcd(a,b))*b)
const ll dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const ll dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vpll dr;
ll n,m,k,h,a1,a2,t;
db prob;
string str;
bool ok = true;
vpll v;
void check(db q , ll b)
{
    ll c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    //temp is too high
    //p is for low
    //q is for high
    //a is for low
    //b is for high
    x = 0;
    for(i=n-1 ; i>=0 ; i--)
    {
        c = v[i].fi;
        d = v[i].se;
        db r = 0;
        if(c==t)
        {
            x = 1;
        }
        if(b-d)
        {

            r = (q-c*d)/(db)(b-d);
        }
        if(r>t)
        {
            b-=d;
            q-=c*d;
        }
        else
        {
            b-=d;
            q-=c*d;
            break;
        }
    }
    //c is temp and d is maximum value of water having temp c
    /*db lo = 0;
    db hi = d;
    z = 0;
    while(z<N)
    {
        z++;
        db mid = lo + (hi-lo)/2.0;
        db temp = 0;
        if(b+mid)
        {
            temp = (q+mid*c)/(db)(b+mid);
        }
        if(temp>=t)
        {
            hi = mid;
        }
        else
        {
            lo = mid;
        }
    }*/
    db val = 0;
    if(t-c)
    {
        val = (q-b*t)/(db)(t-c);
    }
    val+=b;
    showzero;
    val+=h*x;
    ww1(val);
}
int main()
{
    FastIO;
    PRECISION(15);
    ll a,b,c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    db p,q,r,w;
    char ch,chr ;
    string str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //Listen to Zero(Imagine Dragons!!)
    //Listen to Burn(Ellie Goulding)
    //Stay Motivated!!
    //Never use i for two or more nested loops!!
    //Range Query + Constructive + DSU +  Graph Theory + Math + Number Theory + DP(DP + DP with Bitmasks + DP on Trees) + Bitmasks + Data Structures + Strings + Geometry
    //Binary and Ternary Search + Brute Force + Greedy + Implementation
    //In a comparator function comp(pll a , pll b) if comp returns true then a comes before b otherwise b comes berfore a
    //For Longest Common Palindromic Subsequence find the Longest Common subsequence between Original Array and Reverse of the original array
    //Fuck Excuses!!Focus on how to get better
    //First Think then code
    //memset(viv,false,sof(viv));
    //memset(dp,-1,sof(dp));
    //call(dr);
    //1920
    //ThinkThinkThinkThink NOW
    cin>>n>>t;
    v.resz(n);
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].se = a;
    }
    h = 0;
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].fi = a;
        if(a==t)
        {
            h+=v[i].se;
        }
    }
    sort(all(v));
    a = 0; //total volume of water with temp less than T
    p = 0; //total temp with water having temp less than T
    b = 0;//total volume of water with temp more than T
    q = 0;//total temp with water having temp more than T
    for(i=0 ; i<n ; i++)
    {
        if(v[i].fi>=t)
        {
            b+=v[i].se;
            q+=(v[i].se*v[i].fi);
        }
        else
        {
            a+=v[i].se;
            p+=(v[i].se*v[i].fi);
        }
    }
    if(v[n-1].fi<t || v[0].fi>t)
    {
        ww1(0);
        exit(0);
    }
    r = (p+q)/(db)(a+b);
    if(r<t)
    {
        t = -t;
        for(i=0 ; i<n; i++)
        {
            v[i].fi = -v[i].fi;
        }
        sort(all(v));
        p = -p;
        q = -q;

    }
    q+=p;
    b+=a;
    check(q,b);
}
//Always Check for Binary Search(Along with Lower/Upper Bound) , Ternary Search , Greedy then go for DP , DFS , DSU  + Bridge Tree + and other stuff(described above)
//DO IT UNTIL YOU RUN OUT OF IDEAS ~ YOU KNOW WHO
//See The Editorial AN ~ YOU KNOW WHO


/*In Case of TLE -> 1.Use Int instead of Long Long
                    2.Use FastIO
                    3.Use "\n" Instead of endl
                    4.Use Vector and Arrays instead of Sets,Maps(if possible)
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 200003  //N idhar hai
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) >= (b); --(i))
#define rep(i, c) for(auto &(i) : (c))
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define getsm(v) accumulate(all(v),(ll)0)
#define getmx(v) max_element(all(v))
#define getmn(v) min_element(all(v))
#define wr1(a) cout<<(a)<<endl
#define wr2(a,b) cout<<(a)<<" "<<(b)<<endl
#define wr3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define ww1(a) cout<<(a)<<"\n"
#define ww2(a,b) cout<<(a)<<" "<<(b)<<"\n"
#define ww3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define call(dr) dr.pb(mkp(1,0));dr.pb(mkp(-1,0));dr.pb(mkp(0,1));dr.pb(mkp(0,-1))
#define fill(dp,a,b) for(int i=0;i<a;i++)for(int j=0;j<b;j++)dp[i][j]=-1;
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define bitcount( x ) __builtin_popcountll( x )
#define ls(i) (1ll<<(i))
#define rs(i) ((i)>>1)
#define br "\n"
//#define sp " "
using namespace __gnu_pbds; //required
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
double power(double k , long long n ){double res = 1;while(n){if(n%2!=0){res = (res*k) ;}k = (k*k) ;n = n/2 ;}return(res) ;}
ll sign(ll i){if(i==0){return(0);}if(i>0){return(1);}return(-1);}
double distance(pll a , pll b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se-b.se))));}
double distance(pair<ll,pll> a , pair<ll,pll> b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se.fi-b.se.fi) + sqr(a.se.se - b.se.se))));}
//ll lis(vll v){ll d = sz(v);vll dis(d+1,inf);for(ll i = 0 ; i<d ; i++){*lowerB(all(dis),v[i]) = v[i];}for(ll i=0 ; i<d+1 ; i++){if(dis[i]==inf){return(i);}}return(1);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }//for strictly increasing use lower bound(in function lis) otherwhise use upper bound
#define lcm(a,b) ((a/gcd(a,b))*b)
const ll dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const ll dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vpll dr;
ll n,m,k,h,a1,a2,t;
db prob;
string str;
bool ok = true;
vpll v;
void check(db p , db q , ll a , ll b)
{
    ll c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    //temp is too high
    //p is for low
    //q is for high
    //a is for low
    //b is for high
    for(i=n-1 ; i>=0 ; i--)
    {
        c = v[i].fi;
        d = v[i].se;
        db r = (p+q-c*d)/(db)(a+b-d);
        if(r>t)
        {
            b-=d;
            q-=c*d;
        }
        else
        {
            b-=d;
            q-=c*d;
            break;
        }
    }
    //c is temp and d is maximum value of water having temp c
    db lo = 0;
    db hi = d;
    while(hi-lo>1e-10)
    {
        db mid = lo + (hi-lo)/2;
        db temp = (p+q+mid*c)/(db)(a+b+mid);
        if(temp>=t)
        {
            hi = mid;
        }
        else
        {
            lo = mid;
        }
    }
    showzero;
    ww1(a+b+hi);
}
int main()
{
    FastIO;
    PRECISION(10);
    ll a,b,c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    db p,q,r,w;
    char ch,chr ;
    string str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //Listen to Zero(Imagine Dragons!!)
    //Listen to Burn(Ellie Goulding)
    //Stay Motivated!!
    //Never use i for two or more nested loops!!
    //Range Query + Constructive + DSU +  Graph Theory + Math + Number Theory + DP(DP + DP with Bitmasks + DP on Trees) + Bitmasks + Data Structures + Strings + Geometry
    //Binary and Ternary Search + Brute Force + Greedy + Implementation
    //In a comparator function comp(pll a , pll b) if comp returns true then a comes before b otherwise b comes berfore a
    //For Longest Common Palindromic Subsequence find the Longest Common subsequence between Original Array and Reverse of the original array
    //Fuck Excuses!!Focus on how to get better
    //First Think then code
    //memset(viv,false,sof(viv));
    //memset(dp,-1,sof(dp));
    //call(dr);
    //1920
    //ThinkThinkThinkThink NOW
    cin>>n>>t;
    v.resz(n);
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].se = a;
    }
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].fi = a;
    }
    sort(all(v));
    a = 0; //total volume of water with temp less than T
    p = 0; //total temp with water having temp less than T
    b = 0;//total volume of water with temp more than T
    q = 0;//total temp with water having temp more than T
    for(i=0 ; i<n ; i++)
    {
        if(v[i].fi>=t)
        {
            b+=v[i].se;
            q+=(v[i].se*v[i].fi);
        }
        else
        {
            a+=v[i].se;
            p+=(v[i].se*v[i].fi);
        }
    }
    if(!a || !b)
    {
        ww1(-1);
        exit(0);
    }
    r = (p+q)/(db)(a+b);
    if(r<t)
    {
        t = -t;
        for(i=0 ; i<n ; i++)
        {
            v[i].fi = -v[i].fi;
        }
        sort(all(v));
        p = -p;
        q = -q;
        swap(p,q);
    }
    check(p,q,a,b);
}
//Always Check for Binary Search(Along with Lower/Upper Bound) , Ternary Search , Greedy then go for DP , DFS , DSU  + Bridge Tree + and other stuff(described above)
//DO IT UNTIL YOU RUN OUT OF IDEAS ~ YOU KNOW WHO
//See The Editorial AN ~ YOU KNOW WHO


/*In Case of TLE -> 1.Use Int instead of Long Long
                    2.Use FastIO
                    3.Use "\n" Instead of endl
                    4.Use Vector and Arrays instead of Sets,Maps(if possible)
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 1000003  //N idhar hai
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) >= (b); --(i))
#define rep(i, c) for(auto &(i) : (c))
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define getsm(v) accumulate(all(v),(ll)0)
#define getmx(v) max_element(all(v))
#define getmn(v) min_element(all(v))
#define wr1(a) cout<<(a)<<endl
#define wr2(a,b) cout<<(a)<<" "<<(b)<<endl
#define wr3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define ww1(a) cout<<(a)<<"\n"
#define ww2(a,b) cout<<(a)<<" "<<(b)<<"\n"
#define ww3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define call(dr) dr.pb(mkp(1,0));dr.pb(mkp(-1,0));dr.pb(mkp(0,1));dr.pb(mkp(0,-1))
#define fill(dp,a,b) for(int i=0;i<a;i++)for(int j=0;j<b;j++)dp[i][j]=-1;
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define bitcount( x ) __builtin_popcountll( x )
#define ls(i) (1ll<<(i))
#define rs(i) ((i)>>1)
#define br "\n"
//#define sp " "
using namespace __gnu_pbds; //required
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
double power(double k , long long n ){double res = 1;while(n){if(n%2!=0){res = (res*k) ;}k = (k*k) ;n = n/2 ;}return(res) ;}
ll sign(ll i){if(i==0){return(0);}if(i>0){return(1);}return(-1);}
double distance(pll a , pll b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se-b.se))));}
double distance(pair<ll,pll> a , pair<ll,pll> b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se.fi-b.se.fi) + sqr(a.se.se - b.se.se))));}
//ll lis(vll v){ll d = sz(v);vll dis(d+1,inf);for(ll i = 0 ; i<d ; i++){*lowerB(all(dis),v[i]) = v[i];}for(ll i=0 ; i<d+1 ; i++){if(dis[i]==inf){return(i);}}return(1);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }//for strictly increasing use lower bound(in function lis) otherwhise use upper bound
#define lcm(a,b) ((a/gcd(a,b))*b)
const ll dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const ll dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vpll dr;
ll n,m,k,h,a1,a2,t;
db prob;
string str;
bool ok = true;
vpll v;
void check(db q , ll b)
{
    ll c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    //temp is too high
    //p is for low
    //q is for high
    //a is for low
    //b is for high
    for(i=n-1 ; i>=0 ; i--)
    {
        c = v[i].fi;
        d = v[i].se;
        db r = (q-c*d)/(db)(b-d);
        if(r>t)
        {
            b-=d;
            q-=c*d;
        }
        else
        {
            b-=d;
            q-=c*d;
            break;
        }
    }
    //c is temp and d is maximum value of water having temp c
    db lo = 0;
    db hi = d;
    z = 0;
    while(z<N)
    {
        z++;
        db mid = lo + (hi-lo)/2.0;
        db temp = 0;
        if(b+mid)
        {
            temp = (q+mid*c)/(db)(b+mid);
        }
        if(temp>=t)
        {
            hi = mid;
        }
        else
        {
            lo = mid;
        }
    }
    showzero;
    ww1(b+hi);
}
int main()
{
    FastIO;
    PRECISION(15);
    ll a,b,c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    db p,q,r,w;
    char ch,chr ;
    string str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //Listen to Zero(Imagine Dragons!!)
    //Listen to Burn(Ellie Goulding)
    //Stay Motivated!!
    //Never use i for two or more nested loops!!
    //Range Query + Constructive + DSU +  Graph Theory + Math + Number Theory + DP(DP + DP with Bitmasks + DP on Trees) + Bitmasks + Data Structures + Strings + Geometry
    //Binary and Ternary Search + Brute Force + Greedy + Implementation
    //In a comparator function comp(pll a , pll b) if comp returns true then a comes before b otherwise b comes berfore a
    //For Longest Common Palindromic Subsequence find the Longest Common subsequence between Original Array and Reverse of the original array
    //Fuck Excuses!!Focus on how to get better
    //First Think then code
    //memset(viv,false,sof(viv));
    //memset(dp,-1,sof(dp));
    //call(dr);
    //1920
    //ThinkThinkThinkThink NOW
    cin>>n>>t;
    v.resz(n);
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].se = a;
    }
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].fi = a;
    }
    sort(all(v));
    a = 0; //total volume of water with temp less than T
    p = 0; //total temp with water having temp less than T
    b = 0;//total volume of water with temp more than T
    q = 0;//total temp with water having temp more than T
    for(i=0 ; i<n ; i++)
    {
        if(v[i].fi>=t)
        {
            b+=v[i].se;
            q+=(v[i].se*v[i].fi);
        }
        else
        {
            a+=v[i].se;
            p+=(v[i].se*v[i].fi);
        }
    }
    if(v[n-1].fi<t || v[0].fi>t)
    {
        ww1(0);
        exit(0);
    }
    r = (p+q)/(db)(a+b);
    if(r<t)
    {
        t = -t;
        for(i=0 ; i<n; i++)
        {
            v[i].fi = -v[i].fi;
        }
        sort(all(v));
        p = -p;
        q = -q;
    }
    q+=p;
    b+=a;
    check(q,b);
}
//Always Check for Binary Search(Along with Lower/Upper Bound) , Ternary Search , Greedy then go for DP , DFS , DSU  + Bridge Tree + and other stuff(described above)
//DO IT UNTIL YOU RUN OUT OF IDEAS ~ YOU KNOW WHO
//See The Editorial AN ~ YOU KNOW WHO


/*In Case of TLE -> 1.Use Int instead of Long Long
                    2.Use FastIO
                    3.Use "\n" Instead of endl
                    4.Use Vector and Arrays instead of Sets,Maps(if possible)
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 1000003  //N idhar hai
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) >= (b); --(i))
#define rep(i, c) for(auto &(i) : (c))
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define getsm(v) accumulate(all(v),(ll)0)
#define getmx(v) max_element(all(v))
#define getmn(v) min_element(all(v))
#define wr1(a) cout<<(a)<<endl
#define wr2(a,b) cout<<(a)<<" "<<(b)<<endl
#define wr3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define ww1(a) cout<<(a)<<"\n"
#define ww2(a,b) cout<<(a)<<" "<<(b)<<"\n"
#define ww3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define call(dr) dr.pb(mkp(1,0));dr.pb(mkp(-1,0));dr.pb(mkp(0,1));dr.pb(mkp(0,-1))
#define fill(dp,a,b) for(int i=0;i<a;i++)for(int j=0;j<b;j++)dp[i][j]=-1;
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define bitcount( x ) __builtin_popcountll( x )
#define ls(i) (1ll<<(i))
#define rs(i) ((i)>>1)
#define br "\n"
//#define sp " "
using namespace __gnu_pbds; //required
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
double power(double k , long long n ){double res = 1;while(n){if(n%2!=0){res = (res*k) ;}k = (k*k) ;n = n/2 ;}return(res) ;}
ll sign(ll i){if(i==0){return(0);}if(i>0){return(1);}return(-1);}
double distance(pll a , pll b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se-b.se))));}
double distance(pair<ll,pll> a , pair<ll,pll> b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se.fi-b.se.fi) + sqr(a.se.se - b.se.se))));}
//ll lis(vll v){ll d = sz(v);vll dis(d+1,inf);for(ll i = 0 ; i<d ; i++){*lowerB(all(dis),v[i]) = v[i];}for(ll i=0 ; i<d+1 ; i++){if(dis[i]==inf){return(i);}}return(1);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }//for strictly increasing use lower bound(in function lis) otherwhise use upper bound
#define lcm(a,b) ((a/gcd(a,b))*b)
const ll dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const ll dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vpll dr;
ll n,m,k,h,a1,a2,t;
db prob;
string str;
bool ok = true;
vpll v;
void check(db q , ll b)
{
    ll c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    //temp is too high
    //p is for low
    //q is for high
    //a is for low
    //b is for high
    for(i=n-1 ; i>=0 ; i--)
    {
        c = v[i].fi;
        d = v[i].se;
        db r = 0;
        if(b-d)
        {
            r = (q-c*d)/(db)(b-d);
        }
        if(r>t)
        {
            b-=d;
            q-=c*d;
        }
        else
        {
            b-=d;
            q-=c*d;
            break;
        }
    }
    //c is temp and d is maximum value of water having temp c
    /*db lo = 0;
    db hi = d;
    z = 0;
    while(z<N)
    {
        z++;
        db mid = lo + (hi-lo)/2.0;
        db temp = 0;
        if(b+mid)
        {
            temp = (q+mid*c)/(db)(b+mid);
        }
        if(temp>=t)
        {
            hi = mid;
        }
        else
        {
            lo = mid;
        }
    }*/
    long db val = (q-b*t)/(db)(t-c);
    val+=b;
    showzero;
    ww1(val);
}
int main()
{
    FastIO;
    PRECISION(15);
    ll a,b,c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    db p,q,r,w;
    char ch,chr ;
    string str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //Listen to Zero(Imagine Dragons!!)
    //Listen to Burn(Ellie Goulding)
    //Stay Motivated!!
    //Never use i for two or more nested loops!!
    //Range Query + Constructive + DSU +  Graph Theory + Math + Number Theory + DP(DP + DP with Bitmasks + DP on Trees) + Bitmasks + Data Structures + Strings + Geometry
    //Binary and Ternary Search + Brute Force + Greedy + Implementation
    //In a comparator function comp(pll a , pll b) if comp returns true then a comes before b otherwise b comes berfore a
    //For Longest Common Palindromic Subsequence find the Longest Common subsequence between Original Array and Reverse of the original array
    //Fuck Excuses!!Focus on how to get better
    //First Think then code
    //memset(viv,false,sof(viv));
    //memset(dp,-1,sof(dp));
    //call(dr);
    //1920
    //ThinkThinkThinkThink NOW
    cin>>n>>t;
    v.resz(n);
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].se = a;
    }
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].fi = a;
    }
    sort(all(v));
    a = 0; //total volume of water with temp less than T
    p = 0; //total temp with water having temp less than T
    b = 0;//total volume of water with temp more than T
    q = 0;//total temp with water having temp more than T
    for(i=0 ; i<n ; i++)
    {
        if(v[i].fi>=t)
        {
            b+=v[i].se;
            q+=(v[i].se*v[i].fi);
        }
        else
        {
            a+=v[i].se;
            p+=(v[i].se*v[i].fi);
        }
    }
    if(v[n-1].fi<t || v[0].fi>t)
    {
        ww1(0);
        exit(0);
    }
    r = (p+q)/(db)(a+b);
    if(r<t)
    {
        t = -t;
        for(i=0 ; i<n; i++)
        {
            v[i].fi = -v[i].fi;
        }
        sort(all(v));
        p = -p;
        q = -q;
    }
    q+=p;
    b+=a;
    check(q,b);
}
//Always Check for Binary Search(Along with Lower/Upper Bound) , Ternary Search , Greedy then go for DP , DFS , DSU  + Bridge Tree + and other stuff(described above)
//DO IT UNTIL YOU RUN OUT OF IDEAS ~ YOU KNOW WHO
//See The Editorial AN ~ YOU KNOW WHO


/*In Case of TLE -> 1.Use Int instead of Long Long
                    2.Use FastIO
                    3.Use "\n" Instead of endl
                    4.Use Vector and Arrays instead of Sets,Maps(if possible)
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 1000003  //N idhar hai
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) >= (b); --(i))
#define rep(i, c) for(auto &(i) : (c))
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define getsm(v) accumulate(all(v),(ll)0)
#define getmx(v) max_element(all(v))
#define getmn(v) min_element(all(v))
#define wr1(a) cout<<(a)<<endl
#define wr2(a,b) cout<<(a)<<" "<<(b)<<endl
#define wr3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define ww1(a) cout<<(a)<<"\n"
#define ww2(a,b) cout<<(a)<<" "<<(b)<<"\n"
#define ww3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define call(dr) dr.pb(mkp(1,0));dr.pb(mkp(-1,0));dr.pb(mkp(0,1));dr.pb(mkp(0,-1))
#define fill(dp,a,b) for(int i=0;i<a;i++)for(int j=0;j<b;j++)dp[i][j]=-1;
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define bitcount( x ) __builtin_popcountll( x )
#define ls(i) (1ll<<(i))
#define rs(i) ((i)>>1)
#define br "\n"
//#define sp " "
using namespace __gnu_pbds; //required
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
double power(double k , long long n ){double res = 1;while(n){if(n%2!=0){res = (res*k) ;}k = (k*k) ;n = n/2 ;}return(res) ;}
ll sign(ll i){if(i==0){return(0);}if(i>0){return(1);}return(-1);}
double distance(pll a , pll b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se-b.se))));}
double distance(pair<ll,pll> a , pair<ll,pll> b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se.fi-b.se.fi) + sqr(a.se.se - b.se.se))));}
//ll lis(vll v){ll d = sz(v);vll dis(d+1,inf);for(ll i = 0 ; i<d ; i++){*lowerB(all(dis),v[i]) = v[i];}for(ll i=0 ; i<d+1 ; i++){if(dis[i]==inf){return(i);}}return(1);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }//for strictly increasing use lower bound(in function lis) otherwhise use upper bound
#define lcm(a,b) ((a/gcd(a,b))*b)
const ll dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const ll dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vpll dr;
ll n,m,k,h,a1,a2,t;
db prob;
string str;
bool ok = true;
vpll v;
void check(db q , ll b)
{
    ll c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    //temp is too high
    //p is for low
    //q is for high
    //a is for low
    //b is for high
    for(i=n-1 ; i>=0 ; i--)
    {
        c = v[i].fi;
        d = v[i].se;
        db r = 0;
        if(b-d)
        {
            r = (q-c*d)/(db)(b-d);
        }
        if(r>t)
        {
            b-=d;
            q-=c*d;
        }
        else
        {
            b-=d;
            q-=c*d;
            break;
        }
    }
    //c is temp and d is maximum value of water having temp c
    /*db lo = 0;
    db hi = d;
    z = 0;
    while(z<N)
    {
        z++;
        db mid = lo + (hi-lo)/2.0;
        db temp = 0;
        if(b+mid)
        {
            temp = (q+mid*c)/(db)(b+mid);
        }
        if(temp>=t)
        {
            hi = mid;
        }
        else
        {
            lo = mid;
        }
    }*/
    db val = 0;
    if(t-c)
    {
        val = (q-b*t)/(db)(t-c);
    }
    val+=b;
    showzero;
    val = max(val,(db)h);
    ww1(val);
}
int main()
{
    FastIO;
    PRECISION(15);
    ll a,b,c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    db p,q,r,w;
    char ch,chr ;
    string str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //Listen to Zero(Imagine Dragons!!)
    //Listen to Burn(Ellie Goulding)
    //Stay Motivated!!
    //Never use i for two or more nested loops!!
    //Range Query + Constructive + DSU +  Graph Theory + Math + Number Theory + DP(DP + DP with Bitmasks + DP on Trees) + Bitmasks + Data Structures + Strings + Geometry
    //Binary and Ternary Search + Brute Force + Greedy + Implementation
    //In a comparator function comp(pll a , pll b) if comp returns true then a comes before b otherwise b comes berfore a
    //For Longest Common Palindromic Subsequence find the Longest Common subsequence between Original Array and Reverse of the original array
    //Fuck Excuses!!Focus on how to get better
    //First Think then code
    //memset(viv,false,sof(viv));
    //memset(dp,-1,sof(dp));
    //call(dr);
    //1920
    //ThinkThinkThinkThink NOW
    cin>>n>>t;
    v.resz(n);
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].se = a;
    }
    h = 0;
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].fi = a;
        if(a==t)
        {
            h = max(h,v[i].se);
        }
    }
    sort(all(v));
    a = 0; //total volume of water with temp less than T
    p = 0; //total temp with water having temp less than T
    b = 0;//total volume of water with temp more than T
    q = 0;//total temp with water having temp more than T
    for(i=0 ; i<n ; i++)
    {
        if(v[i].fi>=t)
        {
            b+=v[i].se;
            q+=(v[i].se*v[i].fi);
        }
        else
        {
            a+=v[i].se;
            p+=(v[i].se*v[i].fi);
        }
    }
    if(v[n-1].fi<t || v[0].fi>t)
    {
        ww1(0);
        exit(0);
    }
    r = (p+q)/(db)(a+b);
    if(r<t)
    {
        t = -t;
        for(i=0 ; i<n; i++)
        {
            v[i].fi = -v[i].fi;
        }
        sort(all(v));
        p = -p;
        q = -q;
    }
    q+=p;
    b+=a;
    check(q,b);
}
//Always Check for Binary Search(Along with Lower/Upper Bound) , Ternary Search , Greedy then go for DP , DFS , DSU  + Bridge Tree + and other stuff(described above)
//DO IT UNTIL YOU RUN OUT OF IDEAS ~ YOU KNOW WHO
//See The Editorial AN ~ YOU KNOW WHO


/*In Case of TLE -> 1.Use Int instead of Long Long
                    2.Use FastIO
                    3.Use "\n" Instead of endl
                    4.Use Vector and Arrays instead of Sets,Maps(if possible)
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 1000003  //N idhar hai
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) >= (b); --(i))
#define rep(i, c) for(auto &(i) : (c))
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define getsm(v) accumulate(all(v),(ll)0)
#define getmx(v) max_element(all(v))
#define getmn(v) min_element(all(v))
#define wr1(a) cout<<(a)<<endl
#define wr2(a,b) cout<<(a)<<" "<<(b)<<endl
#define wr3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define ww1(a) cout<<(a)<<"\n"
#define ww2(a,b) cout<<(a)<<" "<<(b)<<"\n"
#define ww3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define call(dr) dr.pb(mkp(1,0));dr.pb(mkp(-1,0));dr.pb(mkp(0,1));dr.pb(mkp(0,-1))
#define fill(dp,a,b) for(int i=0;i<a;i++)for(int j=0;j<b;j++)dp[i][j]=-1;
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define bitcount( x ) __builtin_popcountll( x )
#define ls(i) (1ll<<(i))
#define rs(i) ((i)>>1)
#define br "\n"
//#define sp " "
using namespace __gnu_pbds; //required
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
double power(double k , long long n ){double res = 1;while(n){if(n%2!=0){res = (res*k) ;}k = (k*k) ;n = n/2 ;}return(res) ;}
ll sign(ll i){if(i==0){return(0);}if(i>0){return(1);}return(-1);}
double distance(pll a , pll b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se-b.se))));}
double distance(pair<ll,pll> a , pair<ll,pll> b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se.fi-b.se.fi) + sqr(a.se.se - b.se.se))));}
//ll lis(vll v){ll d = sz(v);vll dis(d+1,inf);for(ll i = 0 ; i<d ; i++){*lowerB(all(dis),v[i]) = v[i];}for(ll i=0 ; i<d+1 ; i++){if(dis[i]==inf){return(i);}}return(1);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }//for strictly increasing use lower bound(in function lis) otherwhise use upper bound
#define lcm(a,b) ((a/gcd(a,b))*b)
const ll dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const ll dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vpll dr;
ll n,m,k,h,a1,a2,t;
db prob;
string str;
bool ok = true;
vpll v;
void check(db q , ll b)
{
    ll c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    //temp is too high
    //p is for low
    //q is for high
    //a is for low
    //b is for high
    x = 0;
    for(i=n-1 ; i>=0 ; i--)
    {
        c = v[i].fi;
        d = v[i].se;
        if(c==t)
        {
            x = 1;
        }
        db r = 0;
        if(b-d)
        {
            r = (q-c*d)/(db)(b-d);
        }
        if(r>t)
        {
            b-=d;
            q-=c*d;
        }
        else
        {
            b-=d;
            q-=c*d;
            break;
        }
    }
    //c is temp and d is maximum value of water having temp c
    /*db lo = 0;
    db hi = d;
    z = 0;
    while(z<N)
    {
        z++;
        db mid = lo + (hi-lo)/2.0;
        db temp = 0;
        if(b+mid)
        {
            temp = (q+mid*c)/(db)(b+mid);
        }
        if(temp>=t)
        {
            hi = mid;
        }
        else
        {
            lo = mid;
        }
    }*/
    db val = 0;
    if(t-c)
    {
        val = (q-b*t)/(db)(t-c);
    }
    val+=b;
    showzero;
    val+=h*x;
    ww1(val);
}
int main()
{
    FastIO;
    PRECISION(15);
    ll a,b,c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    db p,q,r,w;
    char ch,chr ;
    string str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //Listen to Zero(Imagine Dragons!!)
    //Listen to Burn(Ellie Goulding)
    //Stay Motivated!!
    //Never use i for two or more nested loops!!
    //Range Query + Constructive + DSU +  Graph Theory + Math + Number Theory + DP(DP + DP with Bitmasks + DP on Trees) + Bitmasks + Data Structures + Strings + Geometry
    //Binary and Ternary Search + Brute Force + Greedy + Implementation
    //In a comparator function comp(pll a , pll b) if comp returns true then a comes before b otherwise b comes berfore a
    //For Longest Common Palindromic Subsequence find the Longest Common subsequence between Original Array and Reverse of the original array
    //Fuck Excuses!!Focus on how to get better
    //First Think then code
    //memset(viv,false,sof(viv));
    //memset(dp,-1,sof(dp));
    //call(dr);
    //1920
    //ThinkThinkThinkThink NOW
    cin>>n>>t;
    v.resz(n);
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].se = a;
    }
    h = 0;
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].fi = a;
        if(a==t)
        {
            h = max(h,v[i].se);
        }
    }
    sort(all(v));
    a = 0; //total volume of water with temp less than T
    p = 0; //total temp with water having temp less than T
    b = 0;//total volume of water with temp more than T
    q = 0;//total temp with water having temp more than T
    for(i=0 ; i<n ; i++)
    {
        if(v[i].fi>=t)
        {
            b+=v[i].se;
            q+=(v[i].se*v[i].fi);
        }
        else
        {
            a+=v[i].se;
            p+=(v[i].se*v[i].fi);
        }
    }
    if(v[n-1].fi<t || v[0].fi>t)
    {
        ww1(0);
        exit(0);
    }
    r = (p+q)/(db)(a+b);
    if(r<t)
    {
        t = -t;
        for(i=0 ; i<n; i++)
        {
            v[i].fi = -v[i].fi;
        }
        sort(all(v));
        p = -p;
        q = -q;

    }
    q+=p;
    b+=a;
    check(q,b);
}
//Always Check for Binary Search(Along with Lower/Upper Bound) , Ternary Search , Greedy then go for DP , DFS , DSU  + Bridge Tree + and other stuff(described above)
//DO IT UNTIL YOU RUN OUT OF IDEAS ~ YOU KNOW WHO
//See The Editorial AN ~ YOU KNOW WHO


/*In Case of TLE -> 1.Use Int instead of Long Long
                    2.Use FastIO
                    3.Use "\n" Instead of endl
                    4.Use Vector and Arrays instead of Sets,Maps(if possible)
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 200003  //N idhar hai
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) >= (b); --(i))
#define rep(i, c) for(auto &(i) : (c))
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define getsm(v) accumulate(all(v),(ll)0)
#define getmx(v) max_element(all(v))
#define getmn(v) min_element(all(v))
#define wr1(a) cout<<(a)<<endl
#define wr2(a,b) cout<<(a)<<" "<<(b)<<endl
#define wr3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define ww1(a) cout<<(a)<<"\n"
#define ww2(a,b) cout<<(a)<<" "<<(b)<<"\n"
#define ww3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define call(dr) dr.pb(mkp(1,0));dr.pb(mkp(-1,0));dr.pb(mkp(0,1));dr.pb(mkp(0,-1))
#define fill(dp,a,b) for(int i=0;i<a;i++)for(int j=0;j<b;j++)dp[i][j]=-1;
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define bitcount( x ) __builtin_popcountll( x )
#define ls(i) (1ll<<(i))
#define rs(i) ((i)>>1)
#define br "\n"
//#define sp " "
using namespace __gnu_pbds; //required
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
double power(double k , long long n ){double res = 1;while(n){if(n%2!=0){res = (res*k) ;}k = (k*k) ;n = n/2 ;}return(res) ;}
ll sign(ll i){if(i==0){return(0);}if(i>0){return(1);}return(-1);}
double distance(pll a , pll b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se-b.se))));}
double distance(pair<ll,pll> a , pair<ll,pll> b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se.fi-b.se.fi) + sqr(a.se.se - b.se.se))));}
//ll lis(vll v){ll d = sz(v);vll dis(d+1,inf);for(ll i = 0 ; i<d ; i++){*lowerB(all(dis),v[i]) = v[i];}for(ll i=0 ; i<d+1 ; i++){if(dis[i]==inf){return(i);}}return(1);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }//for strictly increasing use lower bound(in function lis) otherwhise use upper bound
#define lcm(a,b) ((a/gcd(a,b))*b)
const ll dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const ll dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vpll dr;
ll n,m,k,h,a1,a2,t;
db prob;
string str;
bool ok = true;
vpll v;
void check(db p , db q , ll a , ll b)
{
    ll c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    //temp is too high
    //p is for low
    //q is for high
    //a is for low
    //b is for high
    for(i=n-1 ; i>=0 ; i--)
    {
        c = v[i].fi;
        d = v[i].se;
        db r = (p+q-c*d)/(db)(a+b-d);
        if(r>t)
        {
            b-=d;
            q-=c*d;
        }
        else
        {
            b-=d;
            q-=c*d;
            break;
        }
    }
    //c is temp and d is maximum value of water having temp c
    db lo = 0;
    db hi = d;
    while(hi-lo>1e-10)
    {
        db mid = lo + (hi-lo)/2;
        db temp = (p+q+mid*c)/(db)(a+b+mid);
        if(temp>=t)
        {
            hi = mid;
        }
        else
        {
            lo = mid;
        }
    }
    showzero;
    ww1(a+b+hi);
}
int main()
{
    FastIO;
    PRECISION(10);
    ll a,b,c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    db p,q,r,w;
    char ch,chr ;
    string str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //Listen to Zero(Imagine Dragons!!)
    //Listen to Burn(Ellie Goulding)
    //Stay Motivated!!
    //Never use i for two or more nested loops!!
    //Range Query + Constructive + DSU +  Graph Theory + Math + Number Theory + DP(DP + DP with Bitmasks + DP on Trees) + Bitmasks + Data Structures + Strings + Geometry
    //Binary and Ternary Search + Brute Force + Greedy + Implementation
    //In a comparator function comp(pll a , pll b) if comp returns true then a comes before b otherwise b comes berfore a
    //For Longest Common Palindromic Subsequence find the Longest Common subsequence between Original Array and Reverse of the original array
    //Fuck Excuses!!Focus on how to get better
    //First Think then code
    //memset(viv,false,sof(viv));
    //memset(dp,-1,sof(dp));
    //call(dr);
    //1920
    //ThinkThinkThinkThink NOW
    cin>>n>>t;
    v.resz(n);
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].se = a;
    }
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].fi = a;
    }
    sort(all(v));
    a = 0; //total volume of water with temp less than T
    p = 0; //total temp with water having temp less than T
    b = 0;//total volume of water with temp more than T
    q = 0;//total temp with water having temp more than T
    for(i=0 ; i<n ; i++)
    {
        if(v[i].fi>=t)
        {
            b+=v[i].se;
            q+=(v[i].se*v[i].fi);
        }
        else
        {
            a+=v[i].se;
            p+=(v[i].se*v[i].fi);
        }
    }
    if(v[n-1].fi<t)
    {
        ww1(-1);
        exit(0);
    }
    r = (p+q)/(db)(a+b);
    if(r<t)
    {
        t = -t;
        for(i=0 ; i<n ; i++)
        {
            v[i].fi = -v[i].fi;
        }
        sort(all(v));
        p = -p;
        q = -q;
        swap(p,q);
    }
    check(p,q,a,b);
}
//Always Check for Binary Search(Along with Lower/Upper Bound) , Ternary Search , Greedy then go for DP , DFS , DSU  + Bridge Tree + and other stuff(described above)
//DO IT UNTIL YOU RUN OUT OF IDEAS ~ YOU KNOW WHO
//See The Editorial AN ~ YOU KNOW WHO


/*In Case of TLE -> 1.Use Int instead of Long Long
                    2.Use FastIO
                    3.Use "\n" Instead of endl
                    4.Use Vector and Arrays instead of Sets,Maps(if possible)
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 10000003  //N idhar hai
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) >= (b); --(i))
#define rep(i, c) for(auto &(i) : (c))
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define getsm(v) accumulate(all(v),(ll)0)
#define getmx(v) max_element(all(v))
#define getmn(v) min_element(all(v))
#define wr1(a) cout<<(a)<<endl
#define wr2(a,b) cout<<(a)<<" "<<(b)<<endl
#define wr3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define ww1(a) cout<<(a)<<"\n"
#define ww2(a,b) cout<<(a)<<" "<<(b)<<"\n"
#define ww3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define call(dr) dr.pb(mkp(1,0));dr.pb(mkp(-1,0));dr.pb(mkp(0,1));dr.pb(mkp(0,-1))
#define fill(dp,a,b) for(int i=0;i<a;i++)for(int j=0;j<b;j++)dp[i][j]=-1;
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define bitcount( x ) __builtin_popcountll( x )
#define ls(i) (1ll<<(i))
#define rs(i) ((i)>>1)
#define br "\n"
//#define sp " "
using namespace __gnu_pbds; //required
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
double power(double k , long long n ){double res = 1;while(n){if(n%2!=0){res = (res*k) ;}k = (k*k) ;n = n/2 ;}return(res) ;}
ll sign(ll i){if(i==0){return(0);}if(i>0){return(1);}return(-1);}
double distance(pll a , pll b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se-b.se))));}
double distance(pair<ll,pll> a , pair<ll,pll> b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se.fi-b.se.fi) + sqr(a.se.se - b.se.se))));}
//ll lis(vll v){ll d = sz(v);vll dis(d+1,inf);for(ll i = 0 ; i<d ; i++){*lowerB(all(dis),v[i]) = v[i];}for(ll i=0 ; i<d+1 ; i++){if(dis[i]==inf){return(i);}}return(1);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }//for strictly increasing use lower bound(in function lis) otherwhise use upper bound
#define lcm(a,b) ((a/gcd(a,b))*b)
const ll dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const ll dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vpll dr;
ll n,m,k,h,a1,a2,t;
db prob;
string str;
bool ok = true;
vpll v;
void check(db q , ll b)
{
    ll c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    //temp is too high
    //p is for low
    //q is for high
    //a is for low
    //b is for high
    for(i=n-1 ; i>=0 ; i--)
    {
        c = v[i].fi;
        d = v[i].se;
        db r = (q-c*d)/(db)(b-d);
        if(r>t)
        {
            b-=d;
            q-=c*d;
        }
        else
        {
            b-=d;
            q-=c*d;
            break;
        }
    }
    //c is temp and d is maximum value of water having temp c
    db lo = 0;
    db hi = d;
    z = 0;
    while(z<N)
    {
        z++;
        db mid = lo + (hi-lo)/2.0;
        db temp = 0;
        if(b+mid)
        {
            temp = (q+mid*c)/(db)(b+mid)
        }
        if(temp>=t)
        {
            hi = mid;
        }
        else
        {
            lo = mid;
        }
    }
    showzero;
    ww1(b+hi);
}
int main()
{
    FastIO;
    PRECISION(15);
    ll a,b,c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    db p,q,r,w;
    char ch,chr ;
    string str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //Listen to Zero(Imagine Dragons!!)
    //Listen to Burn(Ellie Goulding)
    //Stay Motivated!!
    //Never use i for two or more nested loops!!
    //Range Query + Constructive + DSU +  Graph Theory + Math + Number Theory + DP(DP + DP with Bitmasks + DP on Trees) + Bitmasks + Data Structures + Strings + Geometry
    //Binary and Ternary Search + Brute Force + Greedy + Implementation
    //In a comparator function comp(pll a , pll b) if comp returns true then a comes before b otherwise b comes berfore a
    //For Longest Common Palindromic Subsequence find the Longest Common subsequence between Original Array and Reverse of the original array
    //Fuck Excuses!!Focus on how to get better
    //First Think then code
    //memset(viv,false,sof(viv));
    //memset(dp,-1,sof(dp));
    //call(dr);
    //1920
    //ThinkThinkThinkThink NOW
    cin>>n>>t;
    v.resz(n);
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].se = a;
    }
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].fi = a;
    }
    sort(all(v));
    a = 0; //total volume of water with temp less than T
    p = 0; //total temp with water having temp less than T
    b = 0;//total volume of water with temp more than T
    q = 0;//total temp with water having temp more than T
    for(i=0 ; i<n ; i++)
    {
        if(v[i].fi>=t)
        {
            b+=v[i].se;
            q+=(v[i].se*v[i].fi);
        }
        else
        {
            a+=v[i].se;
            p+=(v[i].se*v[i].fi);
        }
    }
    if(v[n-1].fi<t || v[0].fi>t)
    {
        ww1(0);
        exit(0);
    }
    r = (p+q)/(db)(a+b);
    if(r<t)
    {
        t = -t;
        for(i=0 ; i<n; i++)
        {
            v[i].fi = -v[i].fi;
        }
        sort(all(v));
        p = -p;
        q = -q;
    }
    q+=p;
    b+=a;
    check(q,b);
}
//Always Check for Binary Search(Along with Lower/Upper Bound) , Ternary Search , Greedy then go for DP , DFS , DSU  + Bridge Tree + and other stuff(described above)
//DO IT UNTIL YOU RUN OUT OF IDEAS ~ YOU KNOW WHO
//See The Editorial AN ~ YOU KNOW WHO


/*In Case of TLE -> 1.Use Int instead of Long Long
                    2.Use FastIO
                    3.Use "\n" Instead of endl
                    4.Use Vector and Arrays instead of Sets,Maps(if possible)
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 10000003  //N idhar hai
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) >= (b); --(i))
#define rep(i, c) for(auto &(i) : (c))
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define getsm(v) accumulate(all(v),(ll)0)
#define getmx(v) max_element(all(v))
#define getmn(v) min_element(all(v))
#define wr1(a) cout<<(a)<<endl
#define wr2(a,b) cout<<(a)<<" "<<(b)<<endl
#define wr3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define ww1(a) cout<<(a)<<"\n"
#define ww2(a,b) cout<<(a)<<" "<<(b)<<"\n"
#define ww3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define call(dr) dr.pb(mkp(1,0));dr.pb(mkp(-1,0));dr.pb(mkp(0,1));dr.pb(mkp(0,-1))
#define fill(dp,a,b) for(int i=0;i<a;i++)for(int j=0;j<b;j++)dp[i][j]=-1;
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define bitcount( x ) __builtin_popcountll( x )
#define ls(i) (1ll<<(i))
#define rs(i) ((i)>>1)
#define br "\n"
//#define sp " "
using namespace __gnu_pbds; //required
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
double power(double k , long long n ){double res = 1;while(n){if(n%2!=0){res = (res*k) ;}k = (k*k) ;n = n/2 ;}return(res) ;}
ll sign(ll i){if(i==0){return(0);}if(i>0){return(1);}return(-1);}
double distance(pll a , pll b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se-b.se))));}
double distance(pair<ll,pll> a , pair<ll,pll> b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se.fi-b.se.fi) + sqr(a.se.se - b.se.se))));}
//ll lis(vll v){ll d = sz(v);vll dis(d+1,inf);for(ll i = 0 ; i<d ; i++){*lowerB(all(dis),v[i]) = v[i];}for(ll i=0 ; i<d+1 ; i++){if(dis[i]==inf){return(i);}}return(1);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }//for strictly increasing use lower bound(in function lis) otherwhise use upper bound
#define lcm(a,b) ((a/gcd(a,b))*b)
const ll dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const ll dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vpll dr;
ll n,m,k,h,a1,a2,t;
db prob;
string str;
bool ok = true;
vpll v;
void check(db q , ll b)
{
    ll c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    //temp is too high
    //p is for low
    //q is for high
    //a is for low
    //b is for high
    for(i=n-1 ; i>=0 ; i--)
    {
        c = v[i].fi;
        d = v[i].se;
        db r = (q-c*d)/(db)(b-d);
        if(r>t)
        {
            b-=d;
            q-=c*d;
        }
        else
        {
            b-=d;
            q-=c*d;
            break;
        }
    }
    //c is temp and d is maximum value of water having temp c
    db lo = 0;
    db hi = d;
    z = 0;
    while(z<N)
    {
        z++;
        db mid = lo + (hi-lo)/2;
        db temp = (q+mid*c)/(db)(b+mid);
        if(temp>=t)
        {
            hi = mid;
        }
        else
        {
            lo = mid;
        }
    }
    showzero;
    ww1(b+hi);
}
int main()
{
    FastIO;
    PRECISION(15);
    ll a,b,c,d,i,j,x,y,z;//,x1,y1,z1,e,f;
    db p,q,r,w;
    char ch,chr ;
    string str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //Listen to Zero(Imagine Dragons!!)
    //Listen to Burn(Ellie Goulding)
    //Stay Motivated!!
    //Never use i for two or more nested loops!!
    //Range Query + Constructive + DSU +  Graph Theory + Math + Number Theory + DP(DP + DP with Bitmasks + DP on Trees) + Bitmasks + Data Structures + Strings + Geometry
    //Binary and Ternary Search + Brute Force + Greedy + Implementation
    //In a comparator function comp(pll a , pll b) if comp returns true then a comes before b otherwise b comes berfore a
    //For Longest Common Palindromic Subsequence find the Longest Common subsequence between Original Array and Reverse of the original array
    //Fuck Excuses!!Focus on how to get better
    //First Think then code
    //memset(viv,false,sof(viv));
    //memset(dp,-1,sof(dp));
    //call(dr);
    //1920
    //ThinkThinkThinkThink NOW
    cin>>n>>t;
    v.resz(n);
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].se = a;
    }
    for(i=0 ; i<n ; i++)
    {
        cin>>a;
        v[i].fi = a;
    }
    sort(all(v));
    a = 0; //total volume of water with temp less than T
    p = 0; //total temp with water having temp less than T
    b = 0;//total volume of water with temp more than T
    q = 0;//total temp with water having temp more than T
    for(i=0 ; i<n ; i++)
    {
        if(v[i].fi>=t)
        {
            b+=v[i].se;
            q+=(v[i].se*v[i].fi);
        }
        else
        {
            a+=v[i].se;
            p+=(v[i].se*v[i].fi);
        }
    }
    if(v[n-1].fi<t)
    {
        ww1(-1);
        exit(0);
    }
    r = (p+q)/(db)(a+b);
    if(r<t)
    {
        t = -t;
        for(i=0 ; i<n; i++)
        {
            v[i].fi = -v[i].fi;
        }
        sort(all(v));
    }
    q+=p;
    b+=a;
    check(q,b);
}
//Always Check for Binary Search(Along with Lower/Upper Bound) , Ternary Search , Greedy then go for DP , DFS , DSU  + Bridge Tree + and other stuff(described above)
//DO IT UNTIL YOU RUN OUT OF IDEAS ~ YOU KNOW WHO
//See The Editorial AN ~ YOU KNOW WHO


#include <bits/stdc++.h>

using namespace std;

using INT = long long;
using pii = pair<int, int>;
using DO = double;
const int NN = 200010;

int n, T;
int a[NN], t[NN];
vector<pii> pos, neg;
INT ans;

int solve(vector<pii> &pos, vector<pii> &neg) {
	sort(pos.begin(), pos.end(), [&](pii u, pii v) {
		return u.first < v.first;
	});

	INT tmp_neg = 0, sum_neg = 0;
	for(auto v : neg) {
		tmp_neg += 1LL * v.first * v.second;
		sum_neg += v.second;
	}

	INT tmp_pos = 0;
	DO sum_pos = 0;
	for(auto v : pos) {
		if(tmp_pos + 1LL * v.first * v.second > tmp_neg) {
			DO sub = tmp_neg - tmp_pos;
			sum_pos += sub/v.first;
			break;
		}

		tmp_pos += 1LL * v.first * v.second;
		sum_pos += v.second;
	}

	printf("%.20lf\n", ans + (DO)sum_pos + (DO)sum_neg);
	return 0;
}

int main () {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	cin >> n >> T;
	for(int i=1; i<=n; i++) cin >> a[i];
	for(int i=1; i<=n; i++) cin >> t[i];
	for(int i=1; i<=n; i++) t[i] -= T;

	ans = 0;
	for(int i=1; i<=n; i++) if(t[i] == 0) ans += a[i];
	INT pos_sum = 0, neg_sum = 0;

	for(int i=1; i<=n; i++) {
		if(t[i] < 0) neg_sum += a[i] * -t[i], neg.push_back(pii(-t[i], a[i]));
		if(t[i] > 0) pos_sum += a[i] * t[i], pos.push_back(pii(t[i], a[i]));
	}

	if(pos_sum == neg_sum) {
		ans = 0;
		for(int i=1; i<=n; i++) ans += a[i];
		printf("%.20lf\n", (DO) ans);
		return 0;
	}

	if(pos_sum > neg_sum) solve(pos, neg);
	else solve(neg, pos);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using DO = double;
const int NN = 200010;

DO a[NN], t[NN], ans;
int n, T;

int calc(vector<pair<DO, int> > &res, vector<pair<DO, int> > &vec) {
	sort(res.begin(), res.end(), [&](pair<DO, int> u, pair<DO, int> v) {
		return u.first < v.first;
	});

	DO tmp1 = 0;
	DO sum1 = 0;
	for(auto v : vec) {
		sum1 += v.second;
		tmp1 += (DO)v.first * v.second;
	}

	DO sum2 = 0;
	DO tmp2 = 0;
	for(auto v : res) {
		if(tmp2 + (DO)v.first * v.second > tmp1) {
			DO sub = tmp1 - tmp2;
			sum2 += sub / v.first;
			break;
		}
		tmp2 += (DO)v.first * v.second;
		sum2 += v.second;
	}

	printf("%.11lf\n", ans + sum1 + sum2);
	return 0;
}

int main () {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> T;
	for(int i=1; i<=n; i++) cin >> a[i];
	for(int i=1; i<=n; i++) cin >> t[i];
	for(int i=1; i<=n; i++) t[i] -= T;

	ans = 0;
	for(int i=1; i<=n; i++) if(t[i] == 0) ans += a[i];
	vector<pair<DO, int> > res, vec;
	DO pos = 0, neg = 0;
	for(int i=1; i<=n; i++) {
		if(t[i] < 0) neg += a[i] * t[i], res.push_back(make_pair(-t[i], a[i]));
		if(t[i] > 0) pos += a[i] * t[i], vec.push_back(make_pair(t[i], a[i]));
	}

	if(pos == neg) {
		DO sum = 0;
		for(int i=1; i<=n; i++) sum += a[i];
		printf("%.11lf\n", sum); return 0;
	}

	if (pos > neg) {
		calc(vec, res);
		return 0;
	}
	calc(res, vec);

	return 0;
}


#include<bits/stdc++.h>
#define NN 200100
#define x first
#define y second
#define eps 1e-12

using namespace std;
using pii=pair<int, int>;
using DO=long double;

pii p[NN];
int a[NN], t[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	cout<<fixed<<setprecision(20);
	int n, T;
	cin>>n>>T;
	for(int i=1; i<=n; i++) scanf("%d", &a[i]);
	for(int i=1; i<=n; i++) scanf("%d", &t[i]);
	for(int i=1; i<=n; i++) t[i]-=T;
	DO ans=0;
	if(T==0) {
		cout<<ans<<endl;
		return 0;
	}
	vector<int>A, B;
	for(int i=1; i<=n; i++) {
		if(t[i]<0) A.push_back(i);
		if(t[i]>0) B.push_back(i);
		if(t[i]==0) ans+=a[i];
	}
	DO sum1=0, sum2=0;
	for(int v : A) sum1+=abs(t[v])*a[v];
	for(int v : B) sum2+=t[v]*a[v];
	if(sum1>=sum2) for(int v : B) ans+=a[v];
	if(sum2>=sum1) for(int v : A) ans+=a[v];
	if(sum1==sum2) {
		cout<<ans<<endl;
		return 0;
	}
	vector<pii>vec;
	if(sum1>sum2) {
		for(int v : A) vec.push_back(pii(abs(t[v]), v));
	}
	else for(int v : B) vec.push_back(pii(t[v], a[v]));
	sort(vec.begin(), vec.end());
	DO d=fabs(sum1-sum2);
	for(auto p : vec) ans+=p.y;
	for(int i=vec.size()-1; i>=0; i--) {
		int val=vec[i].x, m=vec[i].y;
		if(val*m<d-eps) {
			ans-=m;
			d-=val*m;
			continue;
		}
		ans-=(DO)d/val;
		d=0;
		break;
	}
	cout<<ans<<endl;

	return 0;
}


#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from io import BytesIO

class dict(dict):
    """dict() -> new empty dictionary"""

    def items(self):
        """D.items() -> a set-like object providing a view on D's items"""
        return dict.iteritems(self)

    def keys(self):
        """D.keys() -> a set-like object providing a view on D's keys"""
        return dict.iterkeys(self)

    def values(self):
        """D.values() -> an object providing a view on D's values"""
        return dict.itervalues(self)

def gcd(x, y):
    """greatest common divisor of x and y"""
    while y:
        x, y = y, x % y
    return x

range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')

def main():
    n = int(input())
    c = list(map(int, input()))
    a = list(map(int, input()))

    artists = [[], [], [], []]
    am = [0, 0, 0, 0]
    for i in range(n):
        artists[c[i] * 2 + a[i]].append(i + 1)
        am[c[i] * 2 + a[i]] += 1

    t1 = min(am[1], am[2])
    t2 = min(am[0], abs(am[1] - am[2]))
    t3 = ((am[0] - t2) // 2) + (t2 if am[1] < am[2] else 0)
    t4 = ((am[0] - t2) // 2) + (t2 if am[1] > am[2] else 0)

    p1 = [t3, am[1] - t1, t1, am[3] // 2]
    p2 = [t4, t1, am[2] - t1, am[3] // 2]

    f1 = (am[0] - t2) % 2
    f2 = am[3] % 2

    l1 = p1[0] + p1[1] + p1[2] + p1[3]
    l2 = p2[0] + p2[1] + p2[2] + p2[3]

    if abs(l1 - l2) > 1:
        print(-1)
        return

    if f1 == f2 == 1:
        if abs(l1 - l2) == 0:
            if p1[2]:
                p1[0] += 1
                p1[3] += 1
                p1[2] -= 1
                p2[2] += 1
            elif p2[1]:
                p2[0] += 1
                p2[3] += 1
                p2[1] -= 1
                p1[1] += 1
            else:
                print(-1)
                return
        else:
            print(-1)
            return
    elif f1 == 1:
        if abs(l1 - l2) == 1:
            p1[0] += l1 < l2
            p2[0] += l1 > l2
        else:
            print(-1)
            return
    elif f2 == 1:
        if abs(l1 - l2) == 1:
            if p1[2]:
                p1[2] -= 1
                p1[3] += 1
                p2[2] += 1
            if p2[1]:
                p2[1] -= 1
                p2[3] += 1
                p1[1] += 1
        else:
            print(-1)
            return
    elif abs(l1 - l2) == 1:
        print(-1)
        return

    for i, j in enumerate(p1):
        l = artists[i][:j]
        if l:
            print(*artists[i][:j], end=' ')

if __name__ == '__main__':
    main()


#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from io import BytesIO

class dict(dict):
    """dict() -> new empty dictionary"""

    def items(self):
        """D.items() -> a set-like object providing a view on D's items"""
        return dict.iteritems(self)

    def keys(self):
        """D.keys() -> a set-like object providing a view on D's keys"""
        return dict.iterkeys(self)

    def values(self):
        """D.values() -> an object providing a view on D's values"""
        return dict.itervalues(self)

def gcd(x, y):
    """greatest common divisor of x and y"""
    while y:
        x, y = y, x % y
    return x

range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')

def main():
    n = int(input())
    c = list(map(int, input()))
    a = list(map(int, input()))

    artists = [[], [], [], []]
    am = [0, 0, 0, 0]
    for i in range(n):
        artists[c[i] * 2 + a[i]].append(i + 1)
        am[c[i] * 2 + a[i]] += 1

    t1 = min(am[1], am[2])
    t2 = min(am[0], abs(am[1] - am[2]))
    t3 = ((am[0] - t2) // 2) + (t2 if am[1] < am[2] else 0)
    t4 = ((am[0] - t2) // 2) + (t2 if am[1] > am[2] else 0)

    p1 = [t3, am[1] - t1, t1, am[3] // 2]
    p2 = [t4, t1, am[2] - t1, am[3] // 2]

    f1 = (am[0] - t2) % 2
    f2 = am[3] % 2

    if f1 == f2 == 1:
        if p1[2]:
            p1[0] += 1
            p1[3] += 1
            p1[2] -= 1
            p2[2] += 1
        elif p2[1]:
            p2[0] += 1
            p2[3] += 1
            p2[1] -= 1
            p1[2] += 1
    elif f1:
        p1[0] += sum(p1) < sum(p2)
        p2[0] += sum(p1) > sum(p2)
    elif f2:
        if p1[2]:
            p1[2] -= 1
            p1[3] += 1
            p2[2] += 1
        elif p2[1]:
            p2[1] -= 1
            p2[3] += 1
            p1[1] += 1

    if (sum(p1) + sum(p2) != sum(am)) or (sum(p1) != sum(p2)) or (p1[2] + p1[3] != p2[1] + p2[3]):
        print(-1)
    else:
        for i, j in enumerate(p1):
            l = artists[i][:j]
            if l:
                print(*artists[i][:j], end=' ')

if __name__ == '__main__':
    main()


#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from io import BytesIO

class dict(dict):
    """dict() -> new empty dictionary"""

    def items(self):
        """D.items() -> a set-like object providing a view on D's items"""
        return dict.iteritems(self)

    def keys(self):
        """D.keys() -> a set-like object providing a view on D's keys"""
        return dict.iterkeys(self)

    def values(self):
        """D.values() -> an object providing a view on D's values"""
        return dict.itervalues(self)

def gcd(x, y):
    """greatest common divisor of x and y"""
    while y:
        x, y = y, x % y
    return x

range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')

def main():
    n = int(input())
    c = list(map(int, input()))
    a = list(map(int, input()))

    artists = [[], [], [], []]
    am = [0, 0, 0, 0]
    for i in range(n):
        artists[c[i] * 2 + a[i]].append(i + 1)
        am[c[i] * 2 + a[i]] += 1

    t1 = min(am[1], am[2])
    t2 = min(am[0], abs(am[1] - am[2]))
    t3 = ((am[0] - t2) // 2) + (t2 if am[1] < am[2] else 0)
    t4 = ((am[0] - t2) // 2) + (t2 if am[1] > am[2] else 0)

    p1 = [t3, am[1] - t1, t1, am[3] // 2]
    p2 = [t4, t1, am[2] - t1, am[3] // 2]

    f1 = (am[0] - t2) % 2
    f2 = am[3] % 2

    if f1 == f2 == 1:
        if p1[2]:
            p1[0] += 1
            p1[3] += 1
            p1[2] -= 1
            p2[2] += 1
        elif p2[1]:
            p2[0] += 1
            p2[3] += 1
            p2[1] -= 1
            p1[2] += 1
    elif f1:
        if p1[2]:
            p1[3] += 1
            p1[2] -= 1
            p2[2] += 1
        elif p2[1]:
            p2[3] += 1
            p2[1] -= 1
            p1[2] += 1
    elif f2:
        p1[0] += sum(p1) < sum(p2)
        p2[0] += sum(p1) > sum(p2)

    if (sum(p1) + sum(p2) != sum(am)) or (sum(p1) != sum(p2)) or (p1[2] + p1[3] != p2[1] + p2[3]):
        print(-1)
    else:
        for i, j in enumerate(p1):
            l = artists[i][:j]
            if l:
                print(*artists[i][:j], end=' ')

if __name__ == '__main__':
    main()


#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from io import BytesIO

class dict(dict):
    """dict() -> new empty dictionary"""

    def items(self):
        """D.items() -> a set-like object providing a view on D's items"""
        return dict.iteritems(self)

    def keys(self):
        """D.keys() -> a set-like object providing a view on D's keys"""
        return dict.iterkeys(self)

    def values(self):
        """D.values() -> an object providing a view on D's values"""
        return dict.itervalues(self)

def gcd(x, y):
    """greatest common divisor of x and y"""
    while y:
        x, y = y, x % y
    return x

range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')

def main():
    n = int(input())
    a = zip(map(int, input()), map(int, input()))

    m = [[], [], [], []]
    for i, j in enumerate(a):
        m[j[0] * 2 + j[1]].append(i + 1)

    p1 = [0, 0, len(m[2]), 0]
    p2 = [0, len(m[1]), 0, 0]

    u = min(abs(p1[2] - p2[1]), len(m[3]))
    if p1[2] < p2[1]:
        p1[3] = u
    else:
        p2[3] = u

    p1[3] += (len(m[3]) - u) // 2
    p2[3] += (len(m[3]) - u) // 2

    f1 = (len(m[3]) - u) % 2

    if p1[2] + p1[3] < p2[1] + p2[3]:
        u = min(abs(p1[2] + p1[3] - p2[1] - p2[3]), p2[1])
        p2[1] -= u
        p1[1] += u
    else:
        u = min(abs(p1[2] + p1[3] - p2[1] - p2[3]), p1[2])
        p1[2] -= u
        p2[2] += u

    if p1[2] + p1[3] != p2[1] + p2[3]:
        print(-1)
        return

    l1 = p1[1] + p1[2] + p1[3]
    l2 = p2[1] + p2[2] + p2[3]
    u = min(abs(l1 - l2), len(m[0]))
    if l1 < l2:
        p1[0] = u
    else:
        p2[0] = u

    p1[0] += (len(m[0]) - u) // 2
    p2[0] += (len(m[0]) - u) // 2

    f2 = (len(m[0]) - u) % 2

    l1 = p1[0] + p1[1] + p1[2] + p1[3]
    l2 = p2[0] + p2[1] + p2[2] + p2[3]

    if abs(l1 - l2) > 1:
        print(-1)
        return

    if f1 == f2 == 1:
        if abs(l1 - l2) == 0:
            if p1[2]:
                p1[0] += 1
                p1[3] += 1
                p1[2] -= 1
                p2[2] += 1
            elif p2[1]:
                p2[0] += 1
                p2[3] += 1
                p2[1] -= 1
                p1[1] += 1
            else:
                print(-1)
                return
        else:
            print(-1)
            return
    elif f2 == 1:
        if abs(l1 - l2) == 1:
            p1[0] += l1 < l2
            p2[0] += l1 > l2
        else:
            print(-1)
            return
    elif f1 == 1:
        if abs(l1 - l2) == 1:
            if p1[2]:
                p1[2] -= 1
                p1[3] += 1
                p2[2] += 1
            if p2[1]:
                p2[1] -= 1
                p2[3] += 1
                p1[1] += 1
        else:
            print(-1)
            return
    elif abs(l1 - l2) == 1:
        print(-1)
        return

    s = []
    for i, j in enumerate(p1):
        s += m[i][:j]
    print(*s)

if __name__ == '__main__':
    main()


#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from io import BytesIO

class dict(dict):
    """dict() -> new empty dictionary"""

    def items(self):
        """D.items() -> a set-like object providing a view on D's items"""
        return dict.iteritems(self)

    def keys(self):
        """D.keys() -> a set-like object providing a view on D's keys"""
        return dict.iterkeys(self)

    def values(self):
        """D.values() -> an object providing a view on D's values"""
        return dict.itervalues(self)

def gcd(x, y):
    """greatest common divisor of x and y"""
    while y:
        x, y = y, x % y
    return x

range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')

def main():
    n = int(input())
    c = list(map(int, input()))
    a = list(map(int, input()))

    nc, na = sum(c), sum(a)

    m = {0: [], 1: [], 2: [], 3: []}
    for i, j in enumerate(zip(c, a)):
        m[j[0] * 2 + j[1]].append(i)

    p1 = {0: 0, 1: 0, 2: len(m[2]), 3: 0}
    p2 = {0: 0, 1: len(m[1]), 2: 0, 3: 0}

    u = min(abs(p1[2] - p2[1]), len(m[3]))
    if p1[2] < p2[1]:
        p1[3] = u
    else:
        p2[3] = u

    p1[3] += (len(m[3]) - u) // 2
    p2[3] += (len(m[3]) - u) // 2

    f1 = (len(m[3]) - u) % 2

    if p1[2] + p1[3] < p2[1] + p2[3]:
        u = min(abs(p1[2] + p1[3] - p2[1] - p2[3]), p2[1])
        p2[1] -= u
        p1[1] += u
    else:
        u = min(abs(p1[2] + p1[3] - p2[1] - p2[3]), p1[2])
        p1[2] -= u
        p2[2] += u

    if p1[2] + p1[3] != p2[1] + p2[3]:
        print(-1)
        return

    l1 = p1[1] + p1[2] + p1[3]
    l2 = p2[1] + p2[2] + p2[3]
    u = min(abs(l1 - l2), len(m[0]))
    if l1 < l2:
        p1[0] = u
    else:
        p2[0] = u

    p1[0] += (len(m[0]) - u) // 2
    p2[0] += (len(m[0]) - u) // 2

    f2 = (len(m[0]) - u) % 2

    l1 = p1[0] + p1[1] + p1[2] + p1[3]
    l2 = p2[0] + p2[1] + p2[2] + p2[3]

    if abs(l1 - l2) > 1:
        print(-1)
        return

    if f1 == f2 == 1:
        if abs(l1 - l2) == 0:
            if p1[2]:
                p1[0] += 1
                p1[3] += 1
                p1[2] -= 1
                p2[2] += 1
            elif p2[1]:
                p2[0] += 1
                p2[3] += 1
                p2[1] -= 1
                p1[1] += 1
            else:
                print(-1)
                return
        else:
            print(-1)
            return
    elif f2 == 1:
        if abs(l1 - l2) == 1:
            p1[0] += l1 < l2
            p2[0] += l1 > l2
        else:
            print(-1)
            return
    elif f1 == 1:
        if abs(l1 - l2) == 1:
            if p1[2]:
                p1[2] -= 1
                p1[3] += 1
                p2[2] += 1
            if p2[1]:
                p2[1] -= 1
                p2[3] += 1
                p1[1] += 1
        else:
            print(-1)
            return
    elif abs(l1 - l2) == 1:
        print(-1)
        return

    s = []
    for i, j in p1.items():
        s += m[i][:j]
    print(*[i + 1 for i in s])

if __name__ == '__main__':
    main()


#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from io import BytesIO

class dict(dict):
    """dict() -> new empty dictionary"""

    def items(self):
        """D.items() -> a set-like object providing a view on D's items"""
        return dict.iteritems(self)

    def keys(self):
        """D.keys() -> a set-like object providing a view on D's keys"""
        return dict.iterkeys(self)

    def values(self):
        """D.values() -> an object providing a view on D's values"""
        return dict.itervalues(self)

def gcd(x, y):
    """greatest common divisor of x and y"""
    while y:
        x, y = y, x % y
    return x

range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')

def main():
    n = int(input())
    c = list(map(int, input()))
    a = list(map(int, input()))

    artists = [[], [], [], []]
    am = [0, 0, 0, 0]
    for i in range(n):
        artists[c[i] * 2 + a[i]].append(i + 1)
        am[c[i] * 2 + a[i]] += 1

    t1 = min(am[1], am[2])
    t2 = min(am[0], abs(am[1] - am[2]))
    t3 = ((am[0] - t2) // 2) + (t2 if am[1] < am[2] else 0)
    t4 = ((am[0] - t2) // 2) + (t2 if am[1] > am[2] else 0)

    p1 = [t3, am[1] - t1, t1, am[3] // 2]
    p2 = [t4, t1, am[2] - t1, am[3] // 2]

    f1 = (am[0] - t2) % 2
    f2 = am[3] % 2

    l1 = p1[0] + p1[1] + p1[2] + p1[3]
    l2 = p2[0] + p2[1] + p2[2] + p2[3]

    if abs(l1 - l2) > 1:
        print(-1)
        return

    if f1 == f2 == 1:
        if abs(l1 - l2) == 0:
            if p1[2]:
                p1[0] += 1
                p1[3] += 1
                p1[2] -= 1
                p2[2] += 1
            elif p2[1]:
                p2[0] += 1
                p2[3] += 1
                p2[1] -= 1
                p1[1] += 1
            else:
                print(-1)
                return
        else:
            print(-1)
            return
    elif f1 == 1:
        if abs(l1 - l2) == 1:
            p1[0] += l1 < l2
            p2[0] += l1 > l2
        else:
            print(-1)
            return
    elif f2 == 1:
        if abs(l1 - l2) == 1:
            if p1[2]:
                p1[2] -= 1
                p1[3] += 1
                p2[2] += 1
            if p2[1]:
                p2[1] -= 1
                p2[3] += 1
                p1[1] += 1
        else:
            print(-1)
            return
    elif abs(l1 - l2) == 1:
        print(-1)
        return

   for i, j in enumerate(p1):
       l = artists[i][:j]
       if l:
           print(*artists[i][:j], end=' ')

if __name__ == '__main__':
    main()