Advertisement
MinhNGUYEN2k4

Untitled

Dec 18th, 2021
1,285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. //Nguyen Huu Hoang Minh
  2. #include <bits/stdc++.h>
  3. #define sz(x) int(x.size())
  4. #define all(x) x.begin(),x.end()
  5. #define reset(x) memset(x, 0,sizeof(x))
  6. #define pb push_back
  7. #define mp make_pair
  8. #define fi first
  9. #define se second
  10. #define N 100005
  11. #define remain(x) if (x > MOD) x -= MOD
  12. #define ii pair<int, int>
  13. #define iiii pair< ii , ii >
  14. #define viiii vector< iiii >
  15. #define vi vector<int>
  16. #define vii vector< ii >
  17. #define bit(x, i) (((x) >> (i)) & 1)
  18. #define Task "test"
  19. #define int long long
  20.  
  21. using namespace std;
  22.  
  23. typedef long double ld;
  24. const int inf = 1e10;
  25. const int minf = -1e10;
  26.  
  27. int n, m;
  28. int a[N], b[N];
  29.  
  30. void readfile()
  31. {
  32.     ios_base::sync_with_stdio(false);
  33.     cin.tie(0);cout.tie(0);
  34.     if (fopen(Task".inp","r"))
  35.     {
  36.         freopen(Task".inp","r",stdin);
  37.         //freopen(Task".out","w",stdout);
  38.     }
  39.     cin >> n >> m;
  40.     for(int i=1; i<=n; i++){
  41.         cin >> a[i] >> b[i];
  42.     }
  43. }
  44.  
  45. bool ok(int day){
  46.     int product = 0;
  47.     for(int i=1; i<=n; i++){
  48.         int bi =  b[i]+1;
  49.         int full = day/bi;
  50.         int lef = day%bi;
  51.         product += full*b[i]*a[i] + lef*a[i];
  52.     }
  53.     return product >= m;
  54. }
  55.  
  56. void proc()
  57. {
  58.     int l = 1, r = 1e18;
  59.     while (r-l>0){
  60.         int mid = (l+r)/2;
  61.         if (ok(mid)) r = mid;
  62.         else l = mid+1;
  63.     }
  64.     cout << l;
  65. }
  66.  
  67. signed main()
  68. {
  69.     readfile();
  70.     proc();
  71.     return 0;
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement