fork download
  1. #include <bits/stdc++.h>
  2. #include <cstdint>
  3. #include <iomanip>
  4. #define PowerUp ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
  5. #define BattleMode ll t;cin>>t;while(t--)
  6. #define Thor solve();
  7. #define Thunder if(t>0){cout<<line;}
  8. #define ll long long
  9. #define line "\n"
  10. #define line3 cout<<line;
  11. #define stop int abnmj; cin>>abnmj;
  12. #define tap "\t"
  13. #define loop(end,char) for(ll char=0;char<end;char++)
  14. #define loopr(end,char) for(int char=end-1;char>=0;char--)
  15. #define arrin(name) loop(name.size(),p){cin>>name[p];}
  16. #define print(name) for(auto ik:name){cout<<ik<<" ";}
  17. #define print2(name) for(auto ik:name){cout<<ik.first<<" "<<ik.second<<line;}
  18. #define temple template<typename t,typename v>
  19. #define all(x) x.begin(),x.end()
  20. using namespace std;
  21. const double pi = acos(-1);
  22. const ll MOD = 1e9 + 7;
  23. ll magic_powder;
  24. ll cookies_poweder(ll number,vector<ll> &have,vector<ll> &recipe)
  25. {
  26.  
  27. ll sz = have.size();
  28. ll total_powder=0;
  29.  
  30. for (int i = 0; i < sz; i++)
  31. {
  32. ll powder_nedded=recipe[i]*number-have[i];
  33. powder_nedded=((powder_nedded<0) ? (ll)0 : powder_nedded);
  34. total_powder+=powder_nedded;
  35. if (total_powder > magic_powder)
  36. return true;
  37. }
  38. return false;
  39.  
  40. }
  41.  
  42. void solve()
  43. {
  44. ll ingredient;
  45. cin>>ingredient>>magic_powder;
  46.  
  47. vector<ll> recipe(ingredient);
  48. vector<ll> have (ingredient);
  49. arrin(recipe)
  50. arrin(have)
  51.  
  52. ll left=0,mid, right=3*1e9;
  53. while (left < right)
  54. {
  55. mid = (right - left) / 2 + left;
  56. if (cookies_poweder(mid,have,recipe))
  57. right = mid;
  58. else
  59. left = mid+1;
  60. }
  61. if (cookies_poweder(right,have,recipe) )
  62. right--;
  63.  
  64. cout<<right;
  65. }
  66.  
  67. int main()
  68. {
  69. #ifndef ONLINE_JUDGE
  70. freopen("input.txt", "r", stdin);
  71. freopen("output.txt", "w", stdout);
  72. freopen("error.txt", "w", stderr);
  73. #endif
  74. PowerUp
  75. Thor
  76. }
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
3000000000