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. int ans=0;
  35. for(int i=0;i<3;i++){
  36. for(int j=0;j<3;j++){
  37. for(int k=0;k<3;k++){
  38. if(v[0][i].second!=v[1][j].second && v[0][i].second!=v[2][k].second && v[1][j].second!=v[2][k].second)
  39. ans=max(ans,v[0][i].first+v[1][j].first+v[2][k].first);
  40. }
  41. }
  42. }
  43. cout<<ans<<endl;
  44.  
  45.  
  46. }
  47. int main() {
  48. // your code goes here
  49. int t;
  50. cin>>t;
  51. while(t--)solve();
  52. return 0;
  53. }
Success #stdin #stdout 0.01s 5272KB
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
55
56