QOJ.ac

QOJ

Límite de tiempo: 1.0 s Límite de memoria: 2048 MB Puntuación total: 100

#15675. 划艇

Estadísticas

一条河流将 Upper Barareh 与 Lower Barareh 分隔开。为了在这两个城镇之间运送居民,提供了一艘双人船(最多可容纳两人的船),该船具有一定的载重限制。这艘船必须由至少一人驾驶,即在没有任何乘客的情况下,它无法在河上移动。

National Barareh Festival 计划在 Upper Barareh 举行。所有 Lower Barareh 的居民都想参加这个庆典,并需要尽快移动到 Upper Barareh。你的任务是帮助他们以最少的跨河乘船次数移动到 Upper Barareh。

输入格式

输入的第一行包含两个整数 $n$ 和 $w$,其中 $n$ 是 Lower Barareh 的居民人数($1 \le n \le 1000$),$w$ 是船只可以承载的最大重量($1 \le w \le 10^6$)。

下一行包含 $n$ 个空格分隔的整数,描述 Lower Barareh 居民的重量。所有重量均为不超过 $10^6$ 的正整数。

输出格式

如果无法将 Lower Barareh 的所有居民运送过去,则输出单行 -1

否则,输出船只在 Lower Barareh 和 Upper Barareh 之间行驶的最小次数(双向均计入),以便将 Lower Barareh 的所有居民运送到 Upper Barareh。

样例

输入样例 1

3 7
1 3 4

输出样例 1

3

输入样例 2

3 4
2 3 4

输出样例 2

-1

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.