제출 #869966

#제출 시각아이디문제언어결과실행 시간메모리
869966boris_mihovSelf Study (JOI22_ho_t2)C++17
100 / 100
198 ms11624 KiB
#include <algorithm> #include <iostream> #include <numeric> #include <vector> typedef long long llong; const int MAXN = 300000 + 10; const llong INF = 1e18; llong n, m; llong a[MAXN], b[MAXN]; llong achieved[MAXN]; bool check(llong value) { __int128 freeB = 0; for (int i = 1 ; i <= n ; ++i) { llong currLections = std::min(m, (value / a[i] + ((value % a[i]) > 0))); if (value <= m * a[i]) freeB += m - currLections; else { llong moreLections = (value - m * a[i]) / b[i] + (((value - m * a[i]) % b[i]) > 0); freeB -= moreLections; } } return freeB >= 0; } void solve() { llong min = INF; llong max = 0; for (int i = 1 ; i <= n ; ++i) { min = std::min(min, m * a[i]); max = std::max(max, m * a[i]); } llong l = min, r = max + 1, mid; while (l < r - 1) { mid = (l + r) / 2; if (check(mid)) l = mid; else r = mid; } std::cout << l << '\n'; } void read() { std::cin >> n >> m; for (int i = 1 ; i <= n ; ++i) { std::cin >> a[i]; } for (int i = 1 ; i <= n ; ++i) { std::cin >> b[i]; a[i] = std::max(a[i], b[i]); } } void fastIO() { std::ios_base :: sync_with_stdio(0); std::cout.tie(nullptr); std::cin.tie(nullptr); } int main() { fastIO(); 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...