Submission #914865

#TimeUsernameProblemLanguageResultExecution timeMemory
914865andrei_iorgulescuSelf Study (JOI22_ho_t2)C++14
100 / 100
397 ms20744 KiB
#include <bits/stdc++.h> using namespace std; #define int __int128 int n,m,a[300005],b[300005],nev[300005]; int nrparti(int x,int y) { if (x % y == 0) return x / y; return x / y + 1; } bool pot(int x) { int extra = 0; for (int i = 1; i <= n; i++) { nev[i] = x; if (a[i] <= b[i]) extra += m; else { if (x <= m * a[i]) { extra += m - nrparti(x,a[i]); nev[i] = 0; } else { nev[i] = x - m * a[i]; } } } for (int i = 1; i <= n; i++) extra -= nrparti(nev[i],b[i]); if (extra >= 0) return true; return false; } int solvem1() { int ans = 1e9; for (int i = 1; i <= n; i++) ans = min(ans,max(a[i],b[i])); return ans; } int solve() { int st = 0,pas = 1ll << 60; while (pas != 0) { if (pot(st + pas) == true) st += pas; pas /= 2; } return st; } void citire() { long long N,M; cin >> N >> M; n = N,m = M; for (int i = 1; i <= n; i++) { long long X; cin >> X; a[i] = X; } for (int i = 1; i <= n; i++) { long long X; cin >> X; b[i] = X; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); citire(); cout << (long long)solve(); /*srand(0); n = 10; m = 1; while (true) { for (int i = 1; i <= n; i++) a[i] = b[i] = 1 + rand() % 10; if (solvem1() != solve()) { for (int i = 1; i <= n; i++) cout << a[i] << ' '; cout << endl; for (int i = 1; i <= n; i++) cout << b[i] << ' '; } }*/ return 0; } /** 10 1 3 1 1 2 6 1 1 1 1 1 3 1 1 2 6 1 1 1 1 1 **/
#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...