Submission #1123755

#TimeUsernameProblemLanguageResultExecution timeMemory
1123755Neco_arcSelf Study (JOI22_ho_t2)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

#define ll unsigned long long
#define name "Self Study"
#define fi(i, a, b)  for(int i = a; i <= b; ++i)
#define fid(i, a, b) for(int i = a; i >= b; --i)
#define maxn (int) (2e5 + 7)

using namespace std;

ll n, k;
ll a[maxn], b[maxn];

ll cc(ll x, ll y) { return (x / y) + (x % y != 0); }

bool check(ll X) {
    ll S = 0;
    fi(i, 1, n) {

        if(x <= k * a[i]) S += cc(X, a[i]);
        else S += k + cc(X - k * a[i], b[i]);

        if(S > n * k) return 0;
    }
    return 1;
}

void solve() {

    cin >> n >> k;
    fi(i, 1, n) cin >> a[i];
    fi(i, 1, n) cin >> b[i];

    fi(i, 1, n) a[i] = max(a[i], b[i]);

    ll l = 0, r = 1ll << 60;
    while(l <= r) {
        ll mid = (l + r) / 2;
        if(check(mid)) l = mid + 1;
        else r = mid - 1;
    }

    cout << r;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    if(fopen(name".inp", "r")) {
        freopen(name".inp", "r", stdin);
        freopen(name".out", "w", stdout);
    }

    solve();

}

Compilation message (stderr)

Main.cpp: In function 'bool check(long long unsigned int)':
Main.cpp:20:12: error: 'x' was not declared in this scope
   20 |         if(x <= k * a[i]) S += cc(X, a[i]);
      |            ^
Main.cpp: In function 'int main()':
Main.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~