fork download
  1. #include<bits/stdc++.h>
  2. #define FIO ios_base::sync_with_stdio(0);cin.tie(0);
  3. using namespace std;
  4. typedef long long ll;
  5.  
  6. const int MOD=1e9+7, OO=0x3f3f3f3f;
  7. const ll LOO=0x3f3f3f3f3f3f3f3f;
  8. const long double EPS=1e-9;
  9.  
  10.  
  11. bool ok(ll numOfCookies, vector<int>& one, vector<int>& has, int k){
  12. for(int i=0; i<one.size(); i++){
  13. if(numOfCookies * one[i] <= has[i]) continue;
  14. if(k < numOfCookies * one[i] - has[i]) return false;
  15. k -= (numOfCookies * one[i] - has[i]);
  16. }
  17. return true;
  18. }
  19.  
  20. int binarySearch(vector<int>& one, vector<int>& has, int k){
  21. ll low=0, high=2e9;
  22. while(high > low){
  23. ll mid=(low+high+1)/2;
  24. if(ok(mid, one, has, k)) low = mid;
  25. else high = mid-1;
  26. }
  27. return high;
  28. }
  29.  
  30.  
  31. int main(){
  32. FIO
  33. // freopen("input.txt","rt",stdin);
  34. // freopen("output.txt","wt",stdout);
  35. int n,k;
  36. cin>>n>>k;
  37. vector<int>one(n), has(n);
  38. for(auto& x : one) cin>>x;
  39. for(auto& x : has) cin>>x;
  40.  
  41. cout<< binarySearch(one, has, k) <<'\n';
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 5504KB
stdin
3 1
2 1 4
11 3 16
stdout
4