There are friends and types of ramen at the ramen restaurant. Each friend has a certain affinity for ramen type - the greater the affinity, the more friend likes ramen . The affinities of each friend are distinct - i.e., for . Of course, it is possible that .
Suppose the friends visit the ramen restaurant multiple times. During each visit, no two friends can eat the same type of ramen (the supply would be insufficient). Suppose that the friends take their ramen in order , for some permutation of . Then, friend will take their favorite ramen (i.e., the one for which they have the highest affinity), friend will take their favorite ramen except the one taken by , and so on. In other words, will take their favourite ramen among those not taken by .
The goodness of a certain permutation is the sum of the affinities of the friends for the types of ramen they take. In other words, if friend takes ramen of type , then the goodness of is given by .
Your goal is to find a permutation with maximum goodness. You can do this by experimenting with different orders in which the friends take their ramen (i.e., different visits to the restaurant). The goal is to find an optimal permutation without needing too many visits to the restaurant.
Interaction protocol
You have to implement the following function:
std::vector<int> find_order(int N);
Here, is the number of friends. The function should return a permutation of with maximum goodness. To implement it, you may repeatedly call the following function at most times:
std::vector<std::pair<int, int>> query(const std::vector<int>& order);
The function takes as input a permutation of (denoted by the parameter order
) and returns a list of pairs , where is the type of ramen that friend takes if the friends take their ramen in the order given by .
Constraints
- The model solution of the scientific committee requires at most queries for some constants . To not overburden the testing infrastructure, you may call
query
at most times, which generously reflects the practical performance of the model solution.
Example
Competitor behaviour | Committee behaviour |
---|---|
Calls find_order(2) . |
|
query({0, 1}) |
{{0, 9}, {1, 0}} |
query({1, 0}) |
{{1, 5}, {0, 5}} |
find_order(2) returns {1, 0} |
Explanation
In this example, there are friends, with the following affinities for the types of ramen:
The interaction begins with the committee calling your function: find_order(2)
. Your function then queries the two possible permutations: and . The former achieves a goodness of , while the latter achieves a goodness of . The function then returns the better of the two, which is . The returned permutation has the maximum possible goodness, as required.