Submission #1341644

#TimeUsernameProblemLanguageResultExecution timeMemory
1341644iamhereforfunSelf Study (JOI22_ho_t2)C++20
0 / 100
1 ms344 KiB
// Starcraft 2 enjoyer //

#include <bits/stdc++.h>

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define LSOne(X) ((X) & -(X))

const int N = 3e5 + 5;
const int K = 1e2 + 5;
const int M = 2e5 + 5;
const int LG = 20;
const long long INF = 1e18 + 5;
const int C = 26;
const int B = 1000;
const int MOD = 998244353;

long long n, m, a[N], b[N];
long long l, r, ans;

inline void solve()
{
    cin >> n >> m;
    for (int x = 0; x < n; x++)
    {
        cin >> a[x];
    }
    for (int x = 0; x < n; x++)
    {
        cin >> b[x];
        a[x] = max(a[x], b[x]);
    }
    l = 0, r = INF, ans = 0;
    while (l <= r)
    {
        long long md = (l + r) / 2, cnt = 0;
        for (int x = 0; x < n; x++)
        {
            if (cnt > 1LL * n * m)
            {
                break;
            }
            long long i = md;
            if (i > a[x] * m)
            {
                i -= a[x] * m;
                cnt += m;
                cnt += (i - 1) / b[x] + 1;
            }
            else
            {
                cnt += (md - 1) / a[x] + 1;
            }
        }
        if (cnt > 1LL * n * m)
        {
            r = md - 1;
        }
        else
        {
            l = md + 1;
            ans = md;
        }
    }
    cout << ans << "\n";
}

signed main()
{
    freopen("CP.INP", "r", stdin);
    freopen("CP.OUT", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        solve();
    }
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:74:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |     freopen("CP.INP", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:75:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |     freopen("CP.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...