Submission #1159139

#TimeUsernameProblemLanguageResultExecution timeMemory
1159139tw20000807Let's Win the Election (JOI22_ho_t3)C++20
0 / 100
0 ms324 KiB
#include<bits/stdc++.h>
#define int long long
#define all(v) v.begin(), v.end()
#define SZ(x) (int)x.size()
#define pii pair<int, int>
#define X first
#define Y second

using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;//    998244353;
const int llmx = 1e9;

void sol(){
    int n, m;
    cin >> n >> m;
    vector< int > a(n), b(n);
    for(auto &i : a) cin >> i;
    for(auto &i : b) cin >> i;
    for(int i = 0; i < n; ++i) a[i] = max(a[i], b[i]);

    int l = 0, r = 1e18 + 7, ans = 0;
    auto chk = [&](int t) -> bool {
        int free = 0, need = 0;
        for(int i = 0; i < n; ++i){
            if(m * a[i] >= t){
                free += m - (t + a[i] - 1) / a[i];
            }
            else{
                need += (t - a[i] * m + b[i] - 1) / b[i];
            }
            if(need > n * m) return 0;
        }
        return free >= need;
    };
    while(l <= r){
        int mid = (l + r) >> 1;
        if(chk(mid)) l = mid + 1, ans = mid;
        else r = mid - 1;
    }
    cout << ans << "\n";
}
/*
3 3
19 4 5
2 6 2

// 18

2 1
9 7
2 6
// 7

5 60000
630510219 369411957 874325200 990002527 567203997
438920902 634940661 593780254 315929832 420627496
// 41397427274960


4 25
1 2 3 4
1 2 3 4
// 48

*/
signed main(){
    ios::sync_with_stdio(0), cin.tie(0), cerr.tie(0);
    int t = 1; //cin >> t;
    while(t--) sol();
}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...