제출 #1123466

#제출 시각아이디문제언어결과실행 시간메모리
1123466ramzialoulouSelf Study (JOI22_ho_t2)C++20
100 / 100
316 ms5092 KiB
#include <bits/stdc++.h> using namespace std; #ifdef Ramzi #include "debug.h" #else #define debug(...) #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int64_t n, m; cin >> n >> m; vector<int64_t> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int64_t> b(n); for (int i = 0; i < n; i++) { cin >> b[i]; } auto check = [&](int64_t mid) -> bool { int64_t tot = n * m; for (int i = 0; i < n; i++) { int64_t s = 0; if (a[i] > b[i]) { int64_t req = min<int64_t>(m, (mid + a[i] - 1) / a[i]); s = req * a[i]; tot -= req; } int64_t rem = mid - s; if (rem > 0) { int64_t req2 = (rem + b[i] - 1) / b[i]; s += req2 * b[i]; tot -= req2; } if (tot < 0 || s < mid) { return false; } } return true; }; int64_t lo = 0, hi = int64_t(1e18), ans = 0; while (lo <= hi) { int64_t mid = (lo + hi) >> 1; if (check(mid)) { ans = mid; lo = mid + 1; } else { hi = mid - 1; } } cout << ans << "\n"; 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...