fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define faster ios_base::sync_with_stdio(false); cin.tie(NULL)
  4.  
  5. const int N = 1e5 + 7;
  6. const long long INF = 1e16;
  7.  
  8. int X , Y , Z , n;
  9. long long A[N] , B[N];
  10.  
  11. struct gv{
  12. long long a , b , c , d;
  13. } a[N];
  14.  
  15. bool cmp(gv x , gv y){
  16. return x.d > y.d;
  17. }
  18.  
  19. void inp(){
  20. cin >> X >> Y >> Z;
  21. n = X + Y + Z;
  22. }
  23.  
  24. void solve(){
  25. long long Sum = 0;
  26. for(int i = 1 ; i <= n ; i++){
  27. cin >> a[i].a >> a[i].b >> a[i].c;
  28. a[i].d = a[i].a - a[i].b;
  29. Sum += a[i].c;
  30. }
  31.  
  32. sort(a + 1 , a + n + 1 , cmp);
  33.  
  34. priority_queue<long long , vector<long long> , greater<long long>> pq;
  35. long long cur = 0;
  36.  
  37. for(int i = 1 ; i <= n ; i++){
  38. long long val = a[i].a - a[i].c;
  39. pq.push(val);
  40. cur += val;
  41.  
  42. if((int)pq.size() > X){
  43. cur -= pq.top();
  44. pq.pop();
  45. }
  46.  
  47. if(i >= X) A[i] = cur;
  48. }
  49.  
  50. while(!pq.empty()) pq.pop();
  51. cur = 0;
  52.  
  53. for(int i = n ; i >= 1 ; i--){
  54. long long val = a[i].b - a[i].c;
  55. pq.push(val);
  56. cur += val;
  57.  
  58. if((int)pq.size() > Y){
  59. cur -= pq.top();
  60. pq.pop();
  61. }
  62.  
  63. if(n - i + 1 >= Y) B[i] = cur;
  64. }
  65.  
  66. long long ans = -INF;
  67.  
  68. for(int i = X ; i <= n - Y ; i++)
  69. ans = max(ans , A[i] + B[i + 1]);
  70.  
  71. cout << Sum + ans;
  72. }
  73.  
  74. int main(){
  75. faster;
  76. inp();
  77. solve();
  78. return 0;
  79. }
  80.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty