Codeforces Round 916 (Div. 3) 1914D - Three Activitie Solution
Problem Link : https://codeforces.com/problemset/problem/1914/D
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n ; cin >> n ;
- vector<pair<int,int>>a,b,c ;
- int x ;
- for ( int i = 1 ; i <= n ; i++){
- cin >> x ;
- a.push_back({x,i}) ;
- }
- for ( int i = 1 ; i <= n ; i++){
- cin >> x ;
- b.push_back({x,i}) ;
- }
- for ( int i = 1 ; i <= n ; i++){
- cin >> x ;
- c.push_back({x,i}) ;
- }
- sort(a.rbegin(),a.rend()) ;
- sort(b.rbegin(),b.rend()) ;
- sort(c.rbegin(),c.rend()) ;
- int limit = min(n,5) ;
- int ans = INT_MIN ;
- for ( int i = 0 ; i < limit ; i++){
- for ( int j = 0 ; j < limit ; j++){
- for ( int k = 0 ;k < limit ; k++){
- if(a[i].second != b[j].second and b[j].second != c[k].second and a[i].second != c[k].second){
- ans = max(ans , a[i].first + b[j].first + c[k].first) ;
- }
- }
- }
- }
- cout << ans << endl ;
- }
- return 0 ;
- }
No comments