Submission #695782

#TimeUsernameProblemLanguageResultExecution timeMemory
695782etheningSelf Study (JOI22_ho_t2)C++17
100 / 100
496 ms11460 KiB
#include "bits/stdc++.h" #include <functional> using namespace std; using ll = long long; using pii = pair<int, int>; int main() { cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m; vector<ll> 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]); } auto check = [&](ll mid) -> bool { ll freeLesson = 0; for (int i = 0; i < n; i++) { ll numLesson = mid / a[i] + ((mid % a[i] == 0) ? 0 : 1); // cout << "@@@" << i << " " << a[i] << " " << numLesson << endl; if (numLesson < m) { freeLesson += m - numLesson; } } // cout << mid << " " << freeLesson << endl; for (int i = 0; i < n; i++) { ll numLesson = mid / a[i] + ((mid % a[i] == 0) ? 0 : 1); if (numLesson > m) { ll stillNeed = max(0ll, mid - m * a[i]); freeLesson -= stillNeed / b[i] + ((stillNeed % b[i] == 0) ? 0 : 1); } if (freeLesson < 0) return false; } return true; }; ll l = 0; ll r = 1e18; while (l <= r) { ll mid = (l + r) / 2; if (check(mid)) { l = mid + 1; } else { r = mid - 1; } } cout << r << "\n"; }
#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...