fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. #define int long long
  5. #define Nando signed
  6. #define demo main
  7. #define F(i, l, r) for(ll i = l; i <= r; ++i)
  8. #define E(i, l, r) for(int i = l; i >= r; --i)
  9. #define eb emplace_back
  10. const ll mod = 998244353;
  11. const int ars = 2e5 + 5;
  12. const ll il = 1e18;
  13.  
  14. int A, B, C, n;
  15. int a[ars], b[ars], c[ars];
  16. pair<int,int> p[ars];
  17. int f[ars], g[ars];
  18.  
  19. Nando demo() {
  20. ios::sync_with_stdio(0);
  21. cin.tie(0);
  22. cout.tie(0);
  23.  
  24. cin >> A >> B >> C;
  25. n = A + B + C;
  26. F(i, 1, n) cin >> a[i];
  27. F(i, 1, n) cin >> b[i];
  28. F(i, 1, n) cin >> c[i];
  29.  
  30. F(i, 1, n) {
  31. a[i] -= c[i];
  32. b[i] -= c[i];
  33. p[i] = {a[i], b[i]};
  34. }
  35.  
  36. sort(p + 1, p + n + 1, [&](auto &X, auto &Y){
  37. return(X.first - X.second) >(Y.first - Y.second);
  38. });
  39.  
  40. F(i, 1, n) {
  41. a[i] = p[i].first;
  42. b[i] = p[i].second;
  43. }
  44.  
  45. priority_queue<int, vector<int>, greater<int>> pq;
  46. ll sumC = 0, resA = 0;
  47. F(i, 1, n) {
  48. sumC += c[i];
  49. if((int)pq.size() < A) {
  50. pq.push(a[i]);
  51. resA += a[i];
  52. }else if(a[i] > pq.top()) {
  53. resA -= pq.top();
  54. pq.pop();
  55. pq.push(a[i]);
  56. resA += a[i];
  57. }
  58. if((int)pq.size() == A) f[i] = resA + sumC;
  59. else f[i] = -il;
  60. }
  61.  
  62. priority_queue<int, vector<int>, greater<int>> qp;
  63. ll sumC2 = 0, resB = 0;
  64. E(i, n, 1) {
  65. sumC2 += c[i];
  66. if((int)qp.size() < B) {
  67. qp.push(b[i]);
  68. resB += b[i];
  69. }else if(b[i] > qp.top()) {
  70. resB -= qp.top();
  71. qp.pop();
  72. qp.push(b[i]);
  73. resB += b[i];
  74. }
  75. if((int)qp.size() == B) g[i] = resB + sumC2;
  76. else g[i] = -il;
  77. }
  78.  
  79. ll res = 0;
  80. F(i, A, n - B) {
  81. res = max(res, f[i] + g[i + 1]);
  82. }
  83.  
  84. cout << res << "\n";
  85. return 0;
  86. }
  87.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
0