您的位置:首页 > 其它

poj1752 Advertisement(翻译)

2018-01-26 15:40 423 查看

译文

题目描述

娱乐部门已经下定决心要增加盈利,因此决定在当地公园的一条很火的慢跑道上出售广告牌。他们已经在这条道路上建造了许多广告牌,并决定出售在这些广告牌上的广告空间。在慢跑道上,广告牌是均匀分布的,慢跑路径一定一段连续的整数。一个广告牌上只能登出一个广告。

有一天,一位VIP客户想购买一些广告牌,但是需要保证每个慢跑者在沿着小路跑步时都会看到K次ta的广告。

然而,不同的慢跑者会在这条路的不同路段跑步。

通过对慢跑者的调查,我们得到了ta们平时的跑步路径。由于广告商只关注慢跑者所看到的广告牌,所以每个慢跑者的跑步路径都可以用在跑步过程中看到的广告牌的编号来标识。因为广告牌是连续编号的,所以我们完全可以只记录每个慢跑者看到的第一个和最后一个广告牌的号码。

天有不测风云,广告商千算万算,却忽视了一种情况:一些慢跑者在整个跑步过程中看不到K个广告牌。其中的一些人简直懒到令人发指:他们只能看到一个广告牌。由于这些身材走样的慢跑者完全看不到K个广告牌,所以广告商要求ta们在路上看到的每个广告牌上都是ta的广告。这是就是我们所能尽的最大努力了,况且还能够满足客户。

为了减少广告费用,广告商雇佣你去弄清楚至少需要支付的广告牌数量,同时满足规定的要求。

输入

输入的第一行包含两个整数K和N (1 <= K, N <= 1000)。

K是每个慢跑者必须看到的最小广告数,而N是慢跑者的数量。

下面的N行,描述每个慢跑者的路径。

每一行包含两个整数Ai和Bi(两个数字的绝对值不大于10000)。

Ai代表了第一个由第i名慢跑着看到的广告牌编号,Bi是慢跑者看到的最后一个广告牌编号。在跑步过程中,第i名慢跑者将会看到广告牌Ai, Bi以及ta们之间所有的广告牌。

输出

输出文件的第一行,输出一个整数m,表示需要支付的最少广告牌数量,以满足客户的需求。

之后的m行,每行输出一个数字。这些数字(以升序排列)表示广告商的广告应该放在哪个广告牌上。

样例输入

5 10

1 10

20 27

0 -3

15 15

8 2

7 30

-1 -10

27 20

2 9

14 21

样例输出

19

-5

-4

-3

-2

-1

0

4

5

6

7

8

15

18

19

20

21

25

26

27

原文

Description

The Department of Recreation has decided that it must be more profitable, and it wants to sell advertising space along a popular jogging path at a local park. They have built a number of billboards (special signs for advertisements) along the path and have decided to sell advertising space on these billboards. Billboards are situated evenly along the jogging path, and they are given consecutive integer numbers corresponding to their order along the path. At most one advertisement can be placed on each billboard.

A particular client wishes to purchase advertising space on these billboards but needs guarantees that every jogger will see it’s advertisement at least K times while running along the path. However, different joggers run along different parts of the path.

Interviews with joggers revealed that each of them has chosen a section of the path which he/she likes to run along every day. Since advertisers care only about billboards seen by joggers, each jogger’s personal path can be identified by the sequence of billboards viewed during a run. Taking into account that billboards are numbered consecutively, it is sufficient to record the first and the last billboard numbers seen by each jogger.

Unfortunately, interviews with joggers also showed that some joggers don’t run far enough to see K billboards. Some of them are in such bad shape that they get to see only one billboard (here, the first and last billboard numbers for their path will be identical). Since out-of-shape joggers won’t get to see K billboards, the client requires that they see an advertisement on every billboard along their section of the path. Although this is not as good as them seeing K advertisements, this is the best that can be done and it’s enough to satisfy the client.

In order to reduce advertising costs, the client hires you to figure out how to minimize the number of billboards they need to pay for and, at the same time, satisfy stated requirements.

Input

The first line of the input contains two integers K and N (1 <= K, N <= 1000) separated by a space. K is the minimal number of advertisements that every jogger must see, and N is the total number of joggers.

The following N lines describe the path of each jogger. Each line contains two integers Ai and Bi (both numbers are not greater than 10000 by absolute value). Ai represents the first billboard number seen by jogger number i and Bi gives the last billboard number seen by that jogger. During a run, jogger i will see billboards Ai, Bi and all billboards between them.

Output

On the fist line of the output file, write a single integer M. This number gives the minimal number of advertisements that should be placed on billboards in order to fulfill the client’s requirements. Then write M lines with one number on each line. These numbers give (in ascending order) the billboard numbers on which the client’s advertisements should be placed.

Sample Input

5 10

1 10

20 27

0 -3

15 15

8 2

7 30

-1 -10

27 20

2 9

14 21

Sample Output

19

-5

-4

-3

-2

-1

0

4

5

6

7

8

15

18

19

20

21

25

26

27
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: