Submission #783329

#TimeUsernameProblemLanguageResultExecution timeMemory
783329thimote75Self Study (JOI22_ho_t2)C++14
100 / 100
317 ms11432 KiB
#include <bits/stdc++.h> #define int long long using namespace std; using idata = vector<int>; int N, M; idata As, Bs; int ceilDiv (int x, int y) { return (x + y - 1) / y; } int solve (int A, int B, int target) { if (A < B) A = B; if (A * M >= target) return M - ceilDiv(target, A); int local = target - A * M; return - ceilDiv(local, B); } bool check (int target) { int res = 0; for (int i = 0; i < N; i ++) { res += solve(As[i], Bs[i], target); if (res < - M * N) return false; } return res >= 0; } signed main () { cin >> N >> M; if (N < 0) { N *= -1; int a, b; cin >> a >> b; As.resize(N, a); Bs.resize(N, b); } else { As.resize(N); Bs.resize(N); for (int i = 0; i < N; i ++) cin >> As[i]; for (int i = 0; i < N; i ++) cin >> Bs[i]; } int a = 0; int b = 2e18; while (b - a > 1) { int c = (a + b) >> 1; if (check(c)) a = c; else b = c; } cout << a << endl; }
#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...