QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#4361. 机场

الإحصائيات

在 EGOI 机场,有 $N$ 条跑道,编号为 $1$ 到 $N$。在该机场,飞机起飞需要 $K$ 分钟,降落需要 $L$ 分钟。在飞机起飞或降落期间,跑道会被该飞机占用 $K$ 或 $L$ 分钟。

JOI-kun 在 EGOI 机场工作。他的工作是安排一个时长为 $T$ 分钟的连续时间段内的起降时刻表。时间段的开始时刻为 $0$。时间段开始后 $t$ 分钟的时刻记为 $t$。时间段的结束时刻为 $T$。

在该时间段内,将有 $M$ 架飞机抵达 EGOI 机场。它们编号为 $1$ 到 $M$。第 $i$ 架飞机($1 \le i \le M$)将在时刻 $A_i$ 开始降落。但飞机 $i$ 使用的跑道尚未确定,将由 JOI-kun 决定。起飞时刻表完全未定。JOI-kun 将决定起飞的飞机数量、每架飞机的起飞时刻以及使用的跑道。

总之,时刻表必须遵守以下规则: 不允许在同一跑道的同一时刻有超过一架飞机起飞或降落。但是,允许一架飞机在另一架飞机在同一跑道上完成起飞或降落后立即开始起飞或降落。 所有起飞和降落都必须在 $T$ 分钟的时间段内完成。即,不允许飞机在时刻 $0$ 之前开始起飞或降落。不允许飞机在时刻 $T$ 之后完成起飞或降落。

JOI-kun 希望安排时刻表以遵守上述规则,并使起飞的飞机数量最大化。

编写一个程序,给定跑道数量、降落飞机数量、时间段长度、起飞所需时间、降落所需时间以及每架飞机开始降落的时刻,计算从 EGOI 机场起飞的飞机的最大可能数量。如果无法安排出符合规则的时刻表,程序应报告这一点。

输入格式

从标准输入读取以下数据。给定值均为整数。

$N \ M \ T \ K \ L$ $A_1 \ A_2 \ \dots \ A_M$

输出格式

向标准输出写入一行。输出应包含从 EGOI 机场起飞的飞机的最大可能数量。如果无法安排出符合规则的时刻表,输出 $-1$。

数据范围

  • $1 \le N \le 100\,000$
  • $1 \le M \le 100\,000$
  • $1 \le T \le 1\,000\,000\,000 \ (= 10^9)$
  • $1 \le K \le T$
  • $1 \le L \le T$
  • $0 \le A_i \le T - L \ (1 \le i \le M)$

子任务

  1. (7 分)$N = 1$
  2. (12 分)$N = 2, \ M \le 20$
  3. (17 分)$N = 2, \ K = 2, \ L = 2$
  4. (28 分)$N = 2$
  5. (11 分)$N \le 100$
  6. (25 分)无附加限制

样例

样例输入 1

2 4 15 3 2
4 1 5 12

样例输出 1

5

样例输入 2

2 6 23 3 6
9 13 1 16 4 8

样例输出 2

-1

样例输入 3

1 5 20 2 1
2 8 11 15 5

样例输出 3

7

样例输入 4

2 6 13 2 2
7 0 1 10 7 4

样例输出 4

5

样例输入 5

4 4 14 2 3
5 6 3 9

样例输出 5

21

样例输入 6

8 15 100 4 7
93 10 74 46 37 64 68 5 38 67 6 48 76 36 21

样例输出 6

170

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.