Ankit_132

D

Dec 19th, 2023
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7. #define ff     first
  8. #define ss     second
  9.  
  10. int main()
  11. {
  12.     _test
  13.     {
  14.         int n;
  15.         cin>>n;
  16.  
  17.         vector<int> a(n), b(n), c(n);
  18.         for(auto &e: a)     cin>>e;
  19.         for(auto &e: b)     cin>>e;
  20.         for(auto &e: c)     cin>>e;
  21.  
  22.         multiset<pair<int, int>> x, y;
  23.  
  24.         for(int i=0; i<n; i++)
  25.         {
  26.             x.insert({b[i], i});
  27.             y.insert({c[i], i});
  28.         }
  29.  
  30.         int ans = 0;
  31.  
  32.         for(int i=0; i<n; i++)
  33.         {
  34.             x.erase({b[i], i});
  35.             y.erase({c[i], i});
  36.  
  37.             if((*x.rbegin()).ss == (*y.rbegin()).ss)
  38.                 ans = max({ans, a[i] + (*(--x.end())).ff + (*(--(--y.end()))).ff,
  39.                                 a[i] + (*(--y.end())).ff + (*(--(--x.end()))).ff});
  40.             else
  41.                 ans = max(ans, a[i] + (*(--x.end())).ff + (*(--y.end())).ff);
  42.  
  43.             x.insert({b[i], i});
  44.             y.insert({c[i], i});
  45.         }
  46.  
  47.         cout<<ans<<"\n";
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment