Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,794 views

Image of Question : 

image 

 

in Online Assessments by Expert (108,110 points)
edited by | 1,794 views

1 Answer

0 like 0 dislike
Best answer

#include<bits/stdc++.h>

using namespace std;

typedef complex<double> base;
typedef long double ld;
typedef long long ll;

#define pb push_back
#define pii pair<int,int>
#define pll pair< ll , ll >
#define vi vector<int>
#define vvi vector< vi >

const int maxn=(int)(1e5+5);
const ll mod=(ll)(1e9+7);
ll a[maxn],b[maxn];
int n;ll m;

bool check(ll mid)
{
    ll add=0;

    for(int i=0;i<n;i++)
    {
        ll now=a[i]-(mid/b[i]);

        add+=max(0ll,now);

        if(add>m)
        {
            return false;
        }
    }

    return true;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);

    cin>>n>>m;

    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    for(int i=0;i<n;i++)
    {
        cin>>b[i];
    }

    ll low=0,high=(ll)(1e18);

    while(low<high)
    {
        ll mid=(low+high)>>1;

        if(check(mid))
        {
            high=mid;
        }
        else
        {
            low=mid+1;
        }
    }

    cout<<low<<endl;

    return 0;
}
by Expert (108,110 points)
edited by