CF141C.Queue
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In the Main Berland Bank n people stand in a queue at the cashier, everyone knows his/her height h__i, and the heights of the other people in the queue. Each of them keeps in mind number a__i — how many people who are taller than him/her and stand in queue in front of him.
After a while the cashier has a lunch break and the people in the queue seat on the chairs in the waiting room in a random order.
When the lunch break was over, it turned out that nobody can remember the exact order of the people in the queue, but everyone remembers his number a__i.
Your task is to restore the order in which the people stood in the queue if it is possible. There may be several acceptable orders, but you need to find any of them. Also, you need to print a possible set of numbers h__i — the heights of people in the queue, so that the numbers a__i are correct.
在主贝尔兰银行,有 n 个人在收银台前排成一队,每个人都清楚自己身高 hi,以及队列中其他人的身高。每个人心中都记着一个数 ai —— 即排在他/她前面、且比他/她高的人的数量。
过了一段时间,收银员去吃午饭,队列中的人随机坐在了等候室的椅子上。
午饭结束后,人们发现谁也无法准确回忆起原先排队的顺序,但每个人都还记得自己的数 ai。
你的任务是:若可能,还原出原先排队的顺序;可能存在多个合法顺序,你只需找出其中任意一种即可。此外,你还需输出一组可能的身高值 hi(即队列中各人的身高),使得所给的 ai 值均成立。
输入格式
The first input line contains integer n — the number of people in the queue (1 ≤ n ≤ 3000). Then n lines contain descriptions of the people as "name__i a__i" (one description on one line), where name__i is a non-empty string consisting of lowercase Latin letters whose length does not exceed 10 characters (the i-th person's name), a__i is an integer (0 ≤ a__i ≤ n - 1), that represents the number of people who are higher and stand in the queue in front of person i. It is guaranteed that all names are different.
第一行输入包含整数 n —— 队列中的人数(1≤n≤3000)。接下来的 n 行每行包含一个人的描述:“name_i a_i”(每行一个描述),其中 name_i 是一个非空字符串,由小写拉丁字母组成,长度不超过 10 个字符(即第 i 个人的名字),ai 是一个整数(0≤ai≤n−1),表示排在第 i 个人前面且身高高于他/她的人数。保证所有名字互不相同。
输出格式
If there's no acceptable order of the people in the queue, print the single line containing "-1" without the quotes. Otherwise, print in n lines the people as "name__i h__i", where h__i is the integer from 1 to 109 (inclusive), the possible height of a man whose name is name__i. Print the people in the order in which they stand in the queue, starting from the head of the queue and moving to its tail. Numbers h__i are not necessarily unique.
如果队列中不存在满足条件的人的排列顺序,则输出单独一行“-1”(不带引号)。否则,输出 n 行,每行为“name__i h__i”,其中 h__i 是一个介于 1 到 109(含端点)之间的整数,表示姓名为 name__i 的人的可能身高。输出顺序应与队列中人的实际站位顺序一致,即从队首开始,依次到队尾。各 h__i 值不一定互异。
输入输出样例
输入#1
4 a 0 b 2 c 0 d 0
输出#1
a 150 c 170 d 180 b 160
输入#2
4 vasya 0 petya 1 manya 3 dunay 3
输出#2
-1
输入解题思路,AI测评打分。不知道怎么写?