Submission #798348

#TimeUsernameProblemLanguageResultExecution timeMemory
798348n3rm1nSelf Study (JOI22_ho_t2)C++17
0 / 100
403 ms9724 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; const long long MAXN = 3e5 + 10; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } long long n, m; long long a[MAXN], b[MAXN]; void read() { cin >> n >> m; for (long long i = 1; i <= n; ++ i) cin >> a[i]; for (long long i = 1; i <= n; ++ i) cin >> b[i]; } long long useda[MAXN], needb[MAXN]; bool check(long long x) { memset(useda, 0, sizeof(useda)); memset(needb, 0, sizeof(needb)); long long suma = 0, sumb = 0; for (long long i = 1; i <= n; ++ i) { if(a[i] > b[i]) { long long times = x / a[i]; if(x % a[i] != 0)times ++; times = min(m, times); useda[i] = times; long long ost = max(1LL * 0, x - times * a[i]); needb[i] = ost / b[i]; if(ost % b[i] != 0)needb[i] ++; } else { needb[i] = x / b[i]; if(x % b[i] != 0)needb[i] ++; } suma += useda[i]; sumb += needb[i]; } return (sumb <= n * m - suma); } void solve() { long long l = 0, r = 1e17, mid, ans = 0; while(l <= r) { mid = (l + r)/2; if(check(mid)) { ans = mid; l = mid + 1; } else r = mid - 1; } cout << ans << endl; } int main() { speed(); read(); solve(); return 0; }
#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...