fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define fo(i,d,c) for(int i=d;i<=c;i++)
  4. #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  5.  
  6. using namespace std;
  7.  
  8. int n;
  9. int l;
  10. struct hieu {
  11. ll a;
  12. ll b;
  13. };
  14. const int N=1e6;
  15. hieu c[N+1];
  16. bool check (ll d, int l, hieu c[])
  17. {
  18. int tmp=0;
  19. fo(i,1,n){
  20. if(c[i].a<d){
  21. tmp=tmp+((d-c[i].a+c[i].b-1)/c[i].b);
  22. }
  23. if(tmp>l){
  24. return 0;
  25. }
  26. }
  27. return 1;
  28. }
  29. ll solve()
  30. {
  31. ll left=0;
  32. ll right=0;
  33. fo(i,1,n){
  34. right=max(right,(ll)c[i].a+l*c[i].b);
  35. }
  36. ll res,mid;
  37. while(left<=right){
  38. mid=(left+right)/2;
  39. if(check(mid,l,c)){
  40. left=mid+1;
  41. res=mid;
  42. }
  43. else{
  44. right=mid-1;
  45. }
  46. }
  47. return res;
  48. }
  49. int main()
  50. {
  51. IOS;
  52. cin>>n>>l;
  53. fo(i,1,n){
  54. cin>>c[i].a;
  55. cin>>c[i].b;
  56. }
  57. cout<<(ll)solve();
  58. return 0;
  59. }
  60.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty