Ankit_132

B

Aug 12th, 2023
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll     long long
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7. #define ff     first
  8. #define ss     second
  9. #define pb     push_back
  10.  
  11. int main()
  12. {
  13.     ios_base::sync_with_stdio(false);
  14.     cin.tie(NULL);
  15.     cout.tie(NULL);
  16.  
  17.     _test
  18.     {
  19.         int n;
  20.         cin>>n;
  21.  
  22.         vector<int> a;
  23.         vector<int> b;
  24.  
  25.         int mmin = 1e9;
  26.  
  27.         for(int i=0; i<n; i++)
  28.         {
  29.             int k;
  30.             cin>>k;
  31.  
  32.             b.resize(k);
  33.  
  34.             for(auto &e: b) cin>>e;
  35.  
  36.             sort(b.begin(), b.end());
  37.  
  38.             mmin = min(mmin, b[0]);
  39.  
  40.             a.pb(b[1]);
  41.         }
  42.  
  43.         sort(a.begin(), a.end());
  44.  
  45.         a[0] = mmin;
  46.  
  47.         cout<<accumulate(a.begin(), a.end(), 0ll)<<"\n";
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment