Submission #1329574

#TimeUsernameProblemLanguageResultExecution timeMemory
1329574Valters07Self Study (JOI22_ho_t2)C++20
54 / 100
96 ms2764 KiB
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define en exit(0);
using namespace std;
const int N = 3e5 + 5;
int a[N], b[N];
bool can(ll mn, int n, int m)
{
    ll need = 0, have = 1ll * n * m;
    // need - how many b[i] choices we need
    // have - how many b[i] choices we have left
    for(int i = 1;i <= n;i++)
    {
        need += (mn + a[i] - 1) / a[i];
        if(need > have)
            return 0;
    }
    return (have >= need);
}
int main()
{
    fio
//    ifstream cin("in.in");
    int n, m;
    cin >> n >> m;
    for(int i = 1;i <= n;i++)
        cin >> a[i];
    for(int i = 1;i <= n;i++)
        cin >> b[i];
    ll l = 1, r = 1e18;
    while(l < r)
    {
        ll mid = (l + r + 1) / 2;
        if(can(mid, n, m))
            l = mid;
        else
            r = mid - 1;
    }
    cout << l;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...