Submission #803742

#TimeUsernameProblemLanguageResultExecution timeMemory
803742vjudge1Self Study (JOI22_ho_t2)C++14
100 / 100
301 ms7352 KiB
#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std ;
const ll N = 3e5 ;
ll n, m, l = 0, r = (1ll << 62ll), a[N + 1], b[N + 1], now[N + 1] ;
signed main()
{
    ios_base::sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
    cin >> n >> m ;
    for(ll i = 1 ; i <= n ; i++)
        cin >> a[i] ;
    for(ll i = 1 ; i <= n ; i++)
        cin >> b[i] ;
    while(l + 1 < r)
    {
        bool flag = 0 ;
        ll mid = (l + r) >> 1, cnt = 0 ;
        for(ll i = 1 ; i <= n ; i++)
        {
            now[i] = 0 ;
            if(a[i] > b[i])
            {
                if(((mid + a[i] - 1) / a[i]) < m)
                {
                    now[i] = ((mid + a[i] - 1) / a[i]) * a[i] ;
                    cnt += ((mid + a[i] - 1) / a[i]) ;
                }
                else
                {
                    now[i] = m * a[i] ;
                    cnt += m ;
                }
            }
        }
        for(ll i = 1 ; i <= n ; i++)
        {
            if(now[i] >= mid)
                continue ;
            cnt += (mid - now[i] + b[i] - 1) / b[i] ;
            if(cnt < 0 || (mid - now[i] + b[i] - 1) / b[i] < 0)
                flag = 1 ;
        }
        if(cnt > n * m || flag)
            r = mid ;
        else
            l = mid ;
    }
    cout << l ;
    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...