fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. int n;
  6. ll x;
  7. int p[100000 + 5],t[100000 + 5];
  8. bool check(ll time)
  9. {
  10. // check sai khi ko du trung can thiet
  11. // con dung trong TH nguoc lai (so trung >= so trung can thiet) :3
  12. ll eggs = 0;
  13. for(int i = 1; i <= n;i ++)
  14. {
  15. if((ll)p[i] > time)continue;
  16. eggs ++;// TH cua qua dau tien
  17. eggs += 1LL * ((time - p[i])/t[i]); // TH sau qua trung dau tien
  18. }
  19. // cout<<eggs<<'\n';
  20. if(eggs >= x)return true;
  21. return false;
  22. }
  23.  
  24. int main()
  25. {
  26. cin>>n>>x;
  27. for(int i = 1; i <= n;i ++)cin>>p[i]>>t[i];
  28.  
  29. ll d = 1,c = 1e18,ans = -1,mid;
  30. while(d <= c)
  31. {
  32. mid = (d + c)/2;
  33. if(check(mid))
  34. {
  35. ans = mid;
  36. c = mid - 1;
  37. }
  38. else d = mid + 1;
  39. }
  40. cout<<ans;
  41. // ez;
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
1