Codeforces Round 916 (Div. 3) 1914D - Three Activitie Solution


 

Problem Link : https://codeforces.com/problemset/problem/1914/D

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int n ; cin >> n ;
  11. vector<pair<int,int>>a,b,c ;
  12. int x ;
  13. for ( int i = 1 ; i <= n ; i++){
  14. cin >> x ;
  15. a.push_back({x,i}) ;
  16. }
  17. for ( int i = 1 ; i <= n ; i++){
  18. cin >> x ;
  19. b.push_back({x,i}) ;
  20. }
  21. for ( int i = 1 ; i <= n ; i++){
  22. cin >> x ;
  23. c.push_back({x,i}) ;
  24. }
  25. sort(a.rbegin(),a.rend()) ;
  26. sort(b.rbegin(),b.rend()) ;
  27. sort(c.rbegin(),c.rend()) ;
  28. int limit = min(n,5) ;
  29. int ans = INT_MIN ;
  30. for ( int i = 0 ; i < limit ; i++){
  31. for ( int j = 0 ; j < limit ; j++){
  32. for ( int k = 0 ;k < limit ; k++){
  33. if(a[i].second != b[j].second and b[j].second != c[k].second and a[i].second != c[k].second){
  34. ans = max(ans , a[i].first + b[j].first + c[k].first) ;
  35. }
  36. }
  37. }
  38. }
  39. cout << ans << endl ;
  40. }
  41. return 0 ;
  42. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.