Submission #1144121

#TimeUsernameProblemLanguageResultExecution timeMemory
1144121Aryan_RainaSelf Study (JOI22_ho_t2)C++20
10 / 100
151 ms9800 KiB
#include <bits/stdc++.h> using namespace std; #define int int64_t #define ar array #define all(v) begin(v), end(v) #define allr(v) rbegin(v), rend(v) #define pb push_back const int INF = 1e10; void solve() { int n, m; cin >> n >> m; vector<int> a(n), b(n); for (int &x : a) cin >> x; for (int &x : b) cin >> x; for (int i = 0; i < n; i++) a[i] = max(a[i], b[i]); vector<int> ind(n); iota(all(ind), 0); sort(all(ind), [&](int i, int j){ if (a[i] == a[j]) return b[j] < b[i]; return a[i] < a[j]; }); auto joke = [&](int ans) { vector<int> nigga(n); for (int i = 0; i < n; i++) nigga[i] = a[i] * m; int i = 0, j = n-1; while (nigga[ind[i]] < ans && i < j) { while (nigga[ind[j]] - a[ind[j]] >= ans && nigga[ind[i]] < ans) { nigga[ind[j]] -= a[ind[j]]; nigga[ind[i]] += b[ind[i]]; } if (nigga[ind[j]] - a[ind[j]] < ans) j--; else i++; } for (int x : nigga) if (x < ans) return false; return true; }; int l = 0, r = 1e18; while (r-l > 1) { int mid = (l + r) / 2; if (joke(mid)) l = mid; else r = mid; } cout << l << '\n'; } 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...