fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. void solve(){
  4. int n;
  5. cin>>n;
  6. vector<vector<pair<int,int>>> v(3,vector<pair<int,int>>(n));
  7. for(int i=0;i<3;i++){
  8. for(int j=0;j<n;j++){
  9. int k;
  10. cin>>k;
  11. pair<int,int> p={k,j+1};
  12. v[i][j]=p;
  13. }
  14. }
  15.  
  16. for(int i=0;i<3;i++){
  17. sort(v[i].begin(),v[i].end(),greater<pair<int,int>>());
  18. }
  19. // vector<vector<pair<int,int>>> v1(3,vector<pair<int,int>>(3));
  20. // for(int i=0;i<3;i++){
  21. // for(int j=0;j<3;j++){
  22. // v1[j][i]=v[i][j];
  23. // }
  24. // }
  25. // for(int i=0;i<3;i++){
  26. // sort(v1[i].begin(),v1[i].end(),greater<pair<int,int>>());
  27. // }
  28. // for(int i=0;i<3;i++){
  29. // for(int j=0;j<3;j++){
  30. // cout<<v1[i][j].first<<v1[i][j].second<<" ";
  31. // }
  32. // cout<<endl;
  33. // }
  34. vector<int> ct(n+1,0);
  35. int cnt=0;
  36. for(int j=0;j<3 && cnt<3;j++){
  37. for(int i=0;i<3;i++){
  38. if(ct[v[i][j].second]<v[i][j].first){
  39. ct[v[i][j].second]=v[i][j].first;
  40. cnt++;
  41. }
  42. }
  43. }
  44. int ans=0;
  45. for(int i=0;i<=n;i++){
  46. ans+=ct[i];
  47. }
  48. cout<<ans<<endl;
  49.  
  50.  
  51. }
  52. int main() {
  53. // your code goes here
  54. int t;
  55. cin>>t;
  56. while(t--)solve();
  57. return 0;
  58. }
Success #stdin #stdout 0.01s 5292KB
stdin
4
3
1 10 1
10 1 1
1 1 10
4
30 20 10 1
30 5 15 20
30 25 10 10
10
5 19 12 3 18 18 6 17 10 13
15 17 19 11 16 3 11 17 17 17
1 17 18 10 15 8 17 3 13 12
10
17 5 4 18 12 4 11 2 16 16
8 4 14 19 3 12 6 7 5 16
3 4 8 11 10 8 10 2 20 3
stdout
30
75
90
39