QOJ.ac

QOJ

Limite de temps : 2.5 s Limite de mémoire : 512 MB Points totaux : 100

#12225. 狄利克雷

Statistiques

四位朋友 Johann、Peter、Gustav 和 Lejeune 计划建造一堵砖墙。他们已经决定墙体应为一个宽 1 分米、高 $N$ 分米的平行六面体,但尚未确定其长度。

附近的商店里有 $T$ 种砖块,由于他们还没有墙体的设计图,他们为每种 $i$(从 1 到 $T$)购买了 $c_i$ 块砖。第 $i$ 种砖块是一个尺寸为 $1 \times 1 \times l_i$ 分米的平行六面体。

由于稳定性问题,所有的砖块都必须水平放置。这意味着每块砖只能用于墙体的一层。要建造高度为 $N$ 的墙,需要形成 $N$ 组砖块。每一组可以包含任意数量的任意类型的砖块,但所有组中砖块的总长度必须相等。

现在朋友们想知道,是否可以使用他们在商店购买的所有砖块来建造这堵墙。

输入格式

输入的第一行包含两个整数 $T$ 和 $N$ —— 分别表示砖块的种类数和墙体所需的高度($1 \le T \le 5$,$1 \le N \le 10$)。

接下来 $T$ 行描述砖块种类。其中第 $i$ 行包含两个整数 $c_i$ 和 $l_i$ —— 分别表示朋友们购买的第 $i$ 种砖块的数量和该种砖块的长度($1 \le c_i \le 64$,$1 \le l_i \le 10^6$)。

输出格式

如果可以在不违反任何要求的情况下建造墙体,请在输出的一行中打印 “Yes”。否则,打印 “No”。

样例

样例输入 1

3 2
1 7
2 5
5 1

样例输出 1

Yes

样例输入 2

3 10
2 14
2 5
1 1

样例输出 2

No

样例输入 3

3 2
1 7
2 5
1 1

样例输出 3

No

说明

在第一个样例中,构建墙体的唯一可能方式是:用第一种砖块中的 1 块和第三种砖块中的 4 块组成一层,用第二种砖块中的所有砖块和第三种砖块中的 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.