제출 #914855

#제출 시각아이디문제언어결과실행 시간메모리
914855andrei_iorgulescuSelf Study (JOI22_ho_t2)C++14
0 / 100
300 ms13168 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int n,m,a[300005],b[300005],nev[300005];

bool pot(int x)
{
    int extra = 0;
    for (int i = 1; i <= n; i++)
    {
        nev[i] = x;
        if (a[i] <= b[i])
            extra += m;
        else
        {
            if (x <= m * a[i])
            {
                extra += m - ((x - 1) / a[i] + 1);
                nev[i] = 0;
            }
            else
            {
                nev[i] = x - m * a[i];
            }
        }
    }
    for (int i = 1; i <= n; i++)
        if (nev[i] != 0)
            extra -= ((nev[i] - 1) / b[i] + 1);
    if (extra >= 0)
        return true;
    return false;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        cin >> b[i];
    int st = 0,pas = 1ll << 60;
    while (pas != 0)
    {
        if (pot(st + pas) == true)
            st += pas;
        pas /= 2;
    }
    cout << st;
    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...