MAGCARI

y2k

May 8th, 2023
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. /*
  2.     Task    :
  3.     Author  : Phumipat C. [MAGCARI]
  4.     Language: C++
  5.     Created : 03 May 2023 [18:53]
  6. */
  7. #include<bits/stdc++.h>
  8. using namespace std;
  9. void solve(){
  10.     int n,ans = 0;
  11.     cin >> n;
  12.     priority_queue<int > heap;
  13.     for(int i=1;i<=n;i++){
  14.         int y,k;
  15.         cin >> y >> k;
  16.         ans+=y;
  17.         heap.push(-(k-y));
  18.     }
  19.     for(int i=1;i<=n/2;i++){
  20.         ans-=heap.top();
  21.         heap.pop();
  22.     }
  23.     cout << ans << '\n';
  24. }
  25. int main(){
  26.     int q;
  27.     cin >> q;
  28.     while(q--){
  29.         solve();
  30.     }
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment