fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6. inline int power(int a, int b) {
  7. int x = 1;
  8. while (b) {
  9. if (b & 1) x *= a;
  10. a *= a;
  11. b >>= 1;
  12. }
  13. return x;
  14. }
  15.  
  16.  
  17. const int M = 1000000007;
  18. const int N = 3e5+9;
  19. const int INF = 2e9+1;
  20. const int LINF = 2000000000000000001;
  21.  
  22. //_ ***************************** START Below *******************************
  23.  
  24. vector<int> a;
  25. vector<int> b;
  26.  
  27. bool isPossible(int n, int mid){
  28.  
  29. int ct = 0;
  30. int rem = mid;
  31.  
  32. for(int i=0; i<n; i++){
  33. if(a[i] >= rem-1 && b[i] >= ct){
  34. rem--;
  35. ct++;
  36. }
  37. }
  38.  
  39. return ct >= mid;
  40.  
  41. }
  42.  
  43. int consistency(int n){
  44.  
  45. int s = 0, e = INF;
  46.  
  47. while(s<e){
  48. int mid = s + (e-s+1)/2;
  49. if(isPossible(n, mid)){
  50. s = mid;
  51. }
  52. else e = mid-1;
  53. }
  54.  
  55. return e;
  56.  
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. void solve() {
  70.  
  71. int n;
  72. cin>>n;
  73.  
  74. a.resize(n);
  75. b.resize(n);
  76. for(int i=0; i<n; i++){
  77. cin >> a[i] >> b[i];
  78. }
  79.  
  80. cout << consistency(n) << endl;
  81.  
  82.  
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89. int32_t main() {
  90. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  91.  
  92. int t = 1;
  93. cin >> t;
  94. while (t--) {
  95. solve();
  96. }
  97.  
  98. return 0;
  99. }
Success #stdin #stdout 0s 5320KB
stdin
4
3
1 2
2 1
1 1
2
0 0
0 1
2
1 0
0 1
4
1 2
2 1
1 1
0 2
stdout
2
1
2
3