fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <stack>
  4. #include <ext/pb_ds/tree_policy.hpp>
  5.  
  6.  
  7. using namespace __gnu_pbds;
  8. using namespace std;
  9.  
  10. /*typedef tree<string, null_type, less_equal<string>, rb_tree_tag, tree_order_statistics_node_update>orderedSet;
  11. void Erase(orderedSet &s, int val) {
  12.   int rank = s.order_of_key(val);
  13.   auto it = s.find_by_order(rank);
  14.   s.erase(it);
  15. }*/
  16.  
  17.  
  18.  
  19. typedef long long ll;
  20. int Fastpow(int Base , int Power , int MOD){
  21. int Result = 1;
  22.  
  23. while(Power){
  24. if(Power & 1){
  25. Result = (Result * Base) % MOD;
  26. }
  27. Base = (Base * Base) % MOD;
  28. Power >>= 1;
  29. }
  30. return Result;
  31. }
  32.  
  33. vector<int> Is_prime(1001, 1);
  34. void sieve ()
  35. {
  36. Is_prime[0] = Is_prime[1] = 1;
  37. for(int i = 2; i * i <= 1000; i++){
  38. if(Is_prime[i]){
  39. for(int j = i*i; j <= 1000; j += i){
  40. Is_prime[j] = 0;
  41. }
  42. }
  43. }
  44. }
  45.  
  46.  
  47. void Henry()
  48. {
  49. ios_base::sync_with_stdio(false);
  50. cin.tie(nullptr);
  51. cout.tie(nullptr);
  52. }
  53.  
  54. void solve() {
  55. int n,k; cin >> n >> k;
  56. vector<int> a(n), b(n);
  57. map<int, int> mp, revMP;
  58. for(int i = 0; i < n; i++) {
  59. cin >> a[i];
  60. mp[a[i]];
  61. }
  62. for(int i = 0; i < n; i++) {
  63. cin >> b[i];
  64. mp[b[i]];
  65. }
  66.  
  67. int id = 1;
  68. for(auto &[ _ , v ] : mp) {
  69. v = id++;
  70. }
  71.  
  72. for(auto &[ _ , v ] : mp) {
  73. revMP[v] = mp[_];
  74. }
  75.  
  76. vector<int>price(id + 1), badPrices(id + 1);
  77. for(int i = 1; i <= n; i++) {
  78. int l = a[i], r = b[i];
  79. price[1]++;
  80. price[r + 1]--;
  81.  
  82. badPrices[l + 1]++;
  83. badPrices[r + 1]--;
  84. }
  85.  
  86. for(int i = 1; i <= id; i++) {
  87. price[i] += price[i - 1];
  88. badPrices[i] += badPrices[i - 1];
  89. }
  90. int ans = 0;
  91. for(int i = 1; i <= id; i++) {
  92. if(badPrices[i] > k)continue;
  93. ans = max(ans, price[i] * revMP[i]);
  94. }
  95. cout << ans << "\n";
  96. }
  97.  
  98.  
  99.  
  100. int main() {
  101. Henry();
  102. int q = 1;
  103. cin >> q;
  104. while (q--) {
  105. solve();
  106. }
  107. return 0;
  108. }
  109.  
  110.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
0