Submission #612372

#TimeUsernameProblemLanguageResultExecution timeMemory
612372boris_mihovSelf Study (JOI22_ho_t2)C++14
0 / 100
514 ms10764 KiB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

typedef long long llong;
const int MAXN = 300000 + 10;
const llong INF = 2e18;

llong n, m;
llong a[MAXN], b[MAXN];
llong achieved[MAXN];

bool check(llong value)
{
    llong freeB = 0;
    for (int i = 1 ; i <= n ; ++i)
    {
        if (b[i] >= a[i])
        {
            llong currLections = (value / b[i] + ((value % b[i]) > 0));
            freeB += m - currLections;
        } else
        {
            llong currLections = std::min(m, (value / a[i] + ((value % a[i]) > 0)));
            if (currLections < m) freeB += m - currLections;
            else
            {
                llong moreLections = std::max(0LL, ((value - m * a[i]) / b[i] + (((value - m * a[i]) % b[i]) > 0)));
                freeB -= moreLections;
            }
        }
    }

    return freeB >= 0;
}

void solve()
{
    llong l = 0, r = INF, mid;
    while (l < r - 1)
    {
        mid = (l + r) / 2;
        if (check(mid)) l = mid;
        else r = mid;
    }

    std::cout << l << '\n';
}

void read()
{
    std::cin >> n >> m;
    for (int i = 1 ; i <= n ; ++i) std::cin >> a[i];
    for (int i = 1 ; i <= n ; ++i) std::cin >> b[i];
}

void fastIO()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIO();
    read();
    solve();

    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...