// Naive O(N^2) solution, which should be much too slow. #include #include #include #include #include using namespace std; std::array, 2> pick_players(const std::array, 2>& choices) { vector remaining_players; for (int i = 0; i < choices[0].size() * 2; ++i) { remaining_players.push_back(i + 1); } std::array, 2> teams; for (int i = 0; i < choices[0].size(); ++i) { for (int t = 0; t <= 1; ++t) { const int choice = choices[t][i]; teams[t].push_back(remaining_players.at(choice)); remaining_players.erase(remaining_players.begin() + choice); } } return teams; } int main() { int N; cin >> N; assert(N % 2 == 0); std::array, 2> choices; choices[0].reserve(N); choices[1].reserve(N); for (int i = 0 ; i < N; ++i) { int choice; cin >> choice; // In the problem statement, the indexes are 1-based. choices[i >= N/2].push_back(choice - 1); } auto teams = pick_players(choices); for (const auto& team: teams) { for (int player : team) { cout << player << " "; } cout << endl; } }