atcoder#ARC111C. [ARC111C] Too Heavy
[ARC111C] Too Heavy
Score : points
Problem Statement
There are people numbered to and pieces of baggage numbered numbered to . Person has a weight of , and Baggage has a weight of . Initially, Person has Baggage . We want to do the operation below zero or more times so that each Person will have Baggage .
- Choose , and swap the baggages of Person and Person .
However, when a person has a piece of baggage with a weight greater than or equal to his/her own weight, the person gets tired and becomes unable to take part in a future operation (that is, we cannot choose him/her as Person or ). Particularly, if , Person cannot take part in any operation.
Determine whether there is a sequence of operations that achieves the objective, and if so, construct one such sequence with the minimum possible number of operations.
Constraints
- is a permutation of .
- All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If no sequence of operations achieves the objective, print -1
.
Otherwise, print a sequence of operations in the following format:
Here, is the number of operations, and represent the people chosen in the -th operation.
If there are multiple solutions, any of them will be accepted.
4
3 4 8 6
5 3 1 3
3 4 2 1
3
3 4
1 3
4 2
Initially, People has pieces of baggage with weights , respectively, so no one is tired.
First, we do the operation choosing Person and . Now, people has pieces of baggage with weights , so no one is tired yet.
Second, we do the operation choosing Person and . Now, people has pieces of baggage with weights , so Person gets tired.
Lastly, we do the operation choosing Person and . Now, people has pieces of baggage with weights , so no one gets tired.
This sequence of operations has made everyone have the right piece of baggage, with the minimum possible number of operations, so it is valid.
4
1 2 3 4
4 3 2 1
4 3 2 1
-1
No sequence of operations achieves the objective.
1
58
998244353
1
0
The objective is already achieved in the initial state.