제출 #1361444

#제출 시각아이디문제언어결과실행 시간메모리
1361444Born_To_LaughSelf Study (JOI22_ho_t2)C++17
0 / 100
200 ms11668 KiB
// Born_To_Laugh - Hughie Do
#include <bits/stdc++.h>
#define alle(AC) AC.begin(), AC.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
[[maybe_unused]] const ll MOD = 998244353, INF = 3e18 + 7;
#define int ll
const int maxn = 3e5 + 10;
int n, m;
ll a[maxn], b[maxn];
bool check(ll val){
    ll cnt = 0;
    vector<int> trash;
    for(int i=1; i<=n; ++i){
        ll num = m * max(a[i], b[i]);
        if(num >= val){
            ll sth = val / max(a[i], b[i]);
            if(sth * max(a[i], b[i]) < val) sth++;
            cnt += m - sth;
        }
        else trash.push_back(i);
    }
    for(auto &i: trash){
        ll sth = (val - m * max(a[i], b[i])) / b[i];
        if(sth * b[i] < val - m * max(a[i], b[i])) sth++;
        cnt -= sth;
    }
    if(cnt >= 0) return 1;
    return 0;
}
void solve(){
    cin >> n >> m;
    for(int i=1; i<=n; ++i) cin >> a[i];
    for(int i=1; i<=n; ++i) cin >> b[i];
    ll lo = 1, hi = INF, res = lo;
    while(lo <= hi){
        ll mid = (lo + hi) >> 1;
        if(check(mid)){
            res = mid;
            lo = mid + 1;
        }
        else hi = mid - 1;
    }
    cout << res << '\n';
}
signed main(){
    // freopen("inp.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…