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