Submission #1177286

#TimeUsernameProblemLanguageResultExecution timeMemory
1177286chikien2009Self Study (JOI22_ho_t2)C++20
0 / 100
1 ms324 KiB
#include <bits/stdc++.h>

using namespace std;

void setup()
{
#ifndef ONLINE_JUDGE
    freopen("test.inp", "r", stdin);
    freopen("test.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int n;
long long m, l, r, mid, res, a[300000], b[300000];

inline bool Check(long long inp)
{
    long long k = 0, g = 0;
    for (int i = 0; i < n; ++i)
    {
        if (a[i] <= b[i])
        {
            k += m - (inp + b[i] - 1) / b[i];
        }
        else
        {
            if (a[i] * m <= inp)
            {
                k -= (inp - a[i] * m + b[i] - 1) / b[i];
            }
            else
            {
                k += (a[i] * m - inp) / a[i];
            }
        }
        while (k < -1e18)
        {
            g--;
            k += 1e18;
        }
        while (k > 1e18)
        {
            g++;
            k -= 1e18;
        }
    }
    return (k >= 0 && g >= 0) || (g >= 1);
}

int main()
{
    setup();

    cin >> n >> m;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i)
    {
        cin >> b[i];
    }
    l = 1;
    r = 2e18;
    while (l <= r)
    {
        mid = (l + r) >> 1;
        if (Check(mid))
        {
            res = mid;
            l = mid + 1;
        }
        else
        {
            r = mid - 1;
        }
    }
    cout << res;
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'void setup()':
Main.cpp:8:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     freopen("test.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:9:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     freopen("test.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...