Ankit_132

E1/E2

Dec 19th, 2023
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  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);
  18.         for(auto &e: a)     cin>>e;
  19.         for(auto &e: b)     cin>>e;
  20.  
  21.         multiset<pair<int, int>> x;
  22.  
  23.         for(int i=0; i<n; i++)
  24.             x.insert({a[i]+b[i], i});
  25.  
  26.         int f = 1;
  27.  
  28.         ll int ans = 0;
  29.  
  30.         while(x.size())
  31.         {
  32.             int i = (*x.rbegin()).ss;
  33.  
  34.             if(f)
  35.             {
  36.                 ans += a[i]-1;
  37.                 x.erase({a[i]+b[i], i});
  38.             }
  39.             else
  40.             {
  41.                 ans -= b[i]-1;
  42.                 x.erase({a[i]+b[i], i});
  43.             }
  44.  
  45.             f ^= 1;
  46.         }
  47.  
  48.         cout<<ans<<"\n";
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment