Submission #1018905

#TimeUsernameProblemLanguageResultExecution timeMemory
1018905vjudge1Self Study (JOI22_ho_t2)C++17
100 / 100
216 ms16628 KiB
#include <bits/stdc++.h>
//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
using namespace std; //using namespace __gnu_pbds; using namespace chrono;
#define ff first
#define ss second
#define pb push_back
#define gan(x) x.begin(),x.end()
#define rgan(x) x.rbegin(),x.rend()
#define ins insert
typedef long long ll;typedef vector<ll> vecs;typedef vector<vector<ll>> matrix;
#define forn(i, n) for (ll i = 0; i < ll(n); i++)
#define forn1(i, n) for (ll i = 1; i <= ll(n); i++)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update
const int mod = 1e9+7; const char nl = '\n';
const ll N = 1e5+5;
const ll inf = 1e18;

bool check ( ll mid , ll n , ll m , vecs v1 , vecs v2) {
	ll timee = 0 ;
	forn ( i , n ) {
		if ( v2 [ i ] > v1 [ i ] ) {
			ll b = ( mid + v2 [ i ] - 1 ) / v2 [ i ] ;
			timee += b;
		}
		else { if ( v1 [ i ] * 1ll * m >= mid ) {
			ll a = ( mid + v1 [ i ] - 1 ) / v1 [ i ] ;
			timee += a ;
		}
		else {
			ll a = m;
			ll b = ( mid - v1 [ i ] * 1ll * a + v2 [ i ] - 1 ) / v2 [ i ] ;
			timee += a + b;
		}
	}
		if ( timee > n * 1ll * m ) return false;
	}
	if ( timee <= n * 1ll * m ) return true;
	return false;
}

void ShikiMoril() {
 ll n, m; cin >> n >> m ;
  vecs v1 ( n ) , v2 ( n ) ;
  forn ( i , n )  cin >> v1 [ i ] ;
  forn ( i ,  n ) cin >> v2 [ i ] ;
  
  ll l = 1 , r = inf ;
  while ( r - l > 1 ) {
	  ll mid  = ( l + r ) >> 1 ;
	  if ( check ( mid  , n , m , v1 , v2  ) ) l = mid;
	  else r = mid;
  }
  if ( check ( r, n , m , v1 , v2 ) ) cout << r ;
  else cout << l ; 
}
signed main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    // void freopen (){ freopen(".in", "r", stdin);freopen(".out", "w", stdout);}
    ll t = 1;  //cin >> t;
    while (t--) {
        ShikiMoril();
    }
    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...