АВТ
Язык:

Дистанционный практикум по программированию

Задачи Online статус Соревнования
Новости Справка СДО
 
Здравствуйте, Гость! Войдите с паролем или зарегистрируйтесь.

52. Шутка с черепахами

Ограничение времени: 2 сек.
Ограничение памяти:65536 КБайт
Баллы:100
Статистика Послать на проверку Задачу добавил debug

There is a famous joke-riddle for children:

Three turtles are crawling along a road. One turtle says: “There are two turtles ahead of me.” The other turtle says: “There are two turtles behind me.” The third turtle says: “There are two turtles ahead of me and two turtles behind me.” How could this have happened?

The answer is — the third turtle is lying!

Now in this problem you have n turtles crawling along a road. Some of them are crawling in a group, so that they do not see members of their group neither ahead nor behind them. Each turtle makes a statement of the form: “There are ai turtles crawling ahead of me and bi turtles crawling behind me.” Your task is to find the minimal number of turtles that must be lying.

Let us formalize this task. Turtle i has xi coordinate. Some turtles may have the same coordinate. Turtle i tells the truth if and only if ai is the number of turtles such that xj > xi and bi is the number of turtles such that xj < xi. Otherwise, turtle i is lying.

Исходные данные

The first line of the input file contains integer number n (1 <= n <= 1000). It is followed by n lines containing numbers ai and bi (0 <= ai, bi <= 1000) that describe statements of each turtle for i from 1 to n.

Результат

On the first line of the output file write an integer number m — the minimal number of turtles that must be lying, followed by m integers — turtles that are lying. Turtles can be printed in any order. If there are different sets of m lying turtles, then print any of them.

Примеры

Исходные данныеРезультат
3
2 0
0 2
2 2
1 3
5
0 2
0 3
2 1
1 2
4 0
2 1 4

Статистика Послать на проверку Обсуждение задачи Автор/источник:
Задачи с соревнований и сборов / Чемпионат мира по программированию (ICPC) / NEERC-2004 /
51. I - Неподходящие элементы 52. 53. K - Королевство магии 54. L - Клетка с животными
 
время генерации 0.14 сек.
© Copyright ВоГУ, АВТ, Носов Д.А., Андрианов И.А.