fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define file(name) if(fopen(name".inp","r")){freopen(name".INP","r",stdin);freopen(name".OUT","w",stdout);}
  4. #define Fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  5. #define int long long
  6. #define endl '\n'
  7. const int N = 1e6 + 5;
  8. const int mod = 1e9 + 7;
  9. int n,k,a[N], b[N];
  10. bool check(int target){
  11. int cnt = 0;
  12. for (int i = 0; i < n; i++){
  13. if (target >= a[i]){
  14. cnt += (target - a[i]) / b[i] + 1;
  15. if (cnt > k) return 1;
  16. }
  17. }
  18. return cnt > k;
  19. }
  20. void sol(){
  21. cin >> n >> k;
  22. for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  23. int l = 0, r = 1e18,res = -1;
  24. while (l <= r){
  25. int m = (l + r) / 2;
  26. if (check(m)){
  27. res = m;
  28. r = m - 1;
  29. }
  30. else l = m + 1;
  31. }
  32. cout << res;
  33. }
  34. signed main(){
  35. Fastio
  36. //file("");
  37. sol();
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
0