#P1466. Permutation Game
Permutation Game
Permutation Game
题面翻译
N个人,每轮leader报数,提供每一轮的leader,报的数字是这一轮的leader-上一轮的leader,每个数字只能被一个人报,每个人只能报一个数字
题目描述
children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation of length . It is an integer sequence such that each integer from to appears exactly once in it.
The game consists of steps. On each step the current leader with index counts out people in clockwise order, starting from the next person. The last one to be pointed at by the leader becomes the new leader.
You are given numbers — indices of leaders in the beginning of each step. Child with number is the first leader in the game.
Write a program which will restore a possible permutation . If there are multiple solutions then print any of them. If there is no solution then print -1.
输入格式
The first line contains two integer numbers , ( ).
The second line contains integer numbers ( ) — indices of leaders in the beginning of each step.
输出格式
Print such permutation of numbers that leaders in the game will be exactly if all the rules are followed. If there are multiple solutions print any of them.
If there is no permutation which satisfies all described conditions print -1.
样例 #1
样例输入 #1
4 5
2 3 1 4 4
样例输出 #1
3 1 2 4
样例 #2
样例输入 #2
3 3
3 1 2
样例输出 #2
-1
提示
Let's follow leadership in the first example:
- Child starts.
- Leadership goes from to .
- Leadership goes from to . As it's greater than , it's going in a circle to .
- Leadership goes from to .
- Leadership goes from to . Thus in circle it still remains at .