fork(1) download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6.  
  7. // Should be Accepted (Fast-I/O)
  8.  
  9. #define EGRY \
  10.   ios_base::sync_with_stdio(false); \
  11.   cin.tie(NULL);
  12.  
  13. const int MAX = 1e6 + 5;
  14.  
  15. void solve()
  16. {
  17. ll n, k;
  18. cin >> n >> k;
  19.  
  20. vector<ll> a(n), b(n);
  21.  
  22. set<ll> prices;
  23.  
  24. for (ll i = 0; i < n; i++)
  25. {
  26. cin >> a[i];
  27. prices.insert(a[i]);
  28. }
  29.  
  30. for (ll i = 0; i < n; i++)
  31. {
  32. cin >> b[i];
  33. prices.insert(b[i]);
  34. }
  35.  
  36. sort(a.begin(), a.end());
  37. sort(b.begin(), b.end());
  38.  
  39. ll max_profit = 0;
  40.  
  41. for (auto &price : prices)
  42. {
  43. ll happy = a.end() - lower_bound(a.begin(), a.end(), price);
  44. ll nothing = lower_bound(b.begin(), b.end(), price) - b.begin();
  45. ll sad = n - happy - nothing;
  46.  
  47. if (sad <= k)
  48. {
  49. max_profit = max(max_profit, price * (happy + sad));
  50. }
  51. }
  52.  
  53. cout << max_profit << endl;
  54. }
  55.  
  56. int main()
  57. {
  58. EGRY ll t = 1;
  59. // cin >> t;
  60.  
  61. while (t--)
  62. {
  63. solve();
  64. }
  65.  
  66. return 0;
  67. }
  68.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
0