Official

C - MAD TEAM Editorial by en_translator


If we try to search all combinations of teammates, the number of choices can be at most \(4.5 \times 10^9\), so you will get TLE.

Problems of the form of “maximum value of minimum value” can sometimes be solved easily by boiling it down to a yes-no problem of “can the answer be more than \(x\)?” and do binary search for the answer.
Now we will consider the yes-no problem.

We are only interested in whether or not each parameter is more than \(x\), so we can compress each parameter to \(1\) or \(0\) depending on whether it exceeds \(x\) or not. Then, there are at most \(2^5=32\) kinds of tuples of parameters, so one can check exhaustively for all possible choices of three members out of the deduplicated members.

The complexity is \(O((NM+2^{MK})\log X)\), where \(M\) denotes the number of kinds of parameters, \(K\) the number of teammates elected, and \(X\) – the upper bound of the binary search.

Sample Code (C++)

#include <iostream>
#include <vector>
#include <array>
#include <set>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector A(N, array<int, 5>{});
    for(auto& a : A) for(int& i : a) cin >> i;
    int ok = 0, ng = 1000000001;
    auto check = [&](int x) -> bool {
        set<int> s;
        for(auto& a : A){
            int bit = 0;
            for(int& i : a){
                bit <<= 1;
                bit |= i >= x;
            }
            s.insert(bit);
        }
        for(int x : s) for(int y : s) for(int z : s){
            if((x | y | z) == 31) return 1;
        }
        return 0;
    };
    while(abs(ok - ng) > 1){
        int cen = (ok + ng) / 2;
        (check(cen) ? ok : ng) = cen;
    }
    cout << ok << endl;
}

Sample Code (Python)

N = int(input())
A = [tuple(map(int, input().split())) for i in range(N)]

def check(x):
    s = set()
    for a in A:
        s.add(sum(1 << i for i in range(5) if a[i] >= x))
    for x in s:
        for y in s:
            for z in s:
                if x | y | z == 31:
                    return True
    return False

ok = 0
ng = 10**9 + 1
while ng - ok > 1:
    cen = (ok + ng) // 2
    if check(cen):
        ok = cen
    else:
        ng = cen
print(ok)

Solution by DP (Dynamic Programming)

Instead of defining the team’s power as the maximum of the members’ powers, we will chose an arbitrary member and adopt the member’s power. Other parameters will be defined similarly. Then one can do the following DP:

\(dp[i][j][k] = {}\)(the maximum possible of value of the minimum parameters adopted, when \(j\) members out of the first \(i\) members is chosen, and the set of adopted parameters is \(k\))

The time complexity is \(O(NKM2^M)\).

Sample Code (C++)
Sample Code (Python)

posted:
last update: