Submission #1126779

#TimeUsernameProblemLanguageResultExecution timeMemory
1126779nguyentunglamSelf Study (JOI22_ho_t2)C++20
0 / 100
210 ms2788 KiB
#include <bits/stdc++.h> #define endl "\n" using namespace std; namespace std { template <int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1); template <typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {} }; template <typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, T val = T()) : std::vector<T>(n, val) {} }; template <class Fun> class y_combinator_result { Fun fun_; public: template <class T> explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)) {} template <class... Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); } }; template <class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); } } // namespace std void solve() { int n, m; cin >> n >> m; vector<int> a(n), b(n); 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]); } long long l = 0, r = 1e18, ans = -1; while (l <= r) { long long mid = l + r >> 1; long long cur = 0; for (int i = 0; i < n; i++) { long long tmp = 1LL * a[i] * m; if (tmp >= mid) { cur += (tmp - mid) / a[i]; } else { cur -= (mid - tmp + b[i] - 1) / b[i]; } } if (cur >= 0) { ans = mid; l = mid + 1; } else r = mid - 1; } assert(ans != -1); cout << ans; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } }
#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...