Submission #624570

#TimeUsernameProblemLanguageResultExecution timeMemory
624570dooompySelf Study (JOI22_ho_t2)C++17
100 / 100
245 ms11444 KiB
#include "bits/stdc++.h" using namespace std; void abc() {cout << endl;} template <typename T, typename ...U> void abc(T a, U ...b) { cout << a << ' ', abc(b...); } template <typename T> void printv(T l, T r) { while (l != r) cout << *l << " \n"[++l == r]; } template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) { return o >> a.first >> a.second; } template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) { return o << '(' << a.first << ", " << a.second << ')'; } template <typename T> ostream& operator << (ostream& o, vector<T> a) { bool is = false; for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;} return o << '}'; } #ifdef local #define test(args...) abc("[" + string(#args) + "]", args) #else #define test(args...) void(0) #endif using ll = long long; ll n, m; ll a[300005], b[300005]; bool able(ll target) { ll debt = 0; for (int i = 0; i < n; i++) { if (a[i] * m >= target) { debt -= m - (target + a[i] - 1) / a[i]; } else { debt += (target - a[i] * m + b[i] - 1) / b[i]; } if (debt > n*m) return false; } return (debt <= 0); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("", "r", stdin); // freopen("", "w", stdout); cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; for (int i = 0; i < n; i++) a[i] = max(a[i], b[i]); ll l = 0, r = 1e18; ll ans = 0; // cout << able(12) << endl; while (l <= r) { ll mid = (l + r) / 2; // cout << l << " " << r << " " << mid << endl; if (able(mid)) { ans = mid; l = mid + 1; } else r = mid - 1; } cout << ans; }
#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...