CF1348E.Phoenix and Berries

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Phoenix is picking berries in his backyard. There are nn shrubs, and each shrub has aia_i red berries and bib_i blue berries.

Each basket can contain kk berries. But, Phoenix has decided that each basket may only contain berries from the same shrub or berries of the same color (red or blue). In other words, all berries in a basket must be from the same shrub or/and have the same color.

For example, if there are two shrubs with 55 red and 22 blue berries in the first shrub and 22 red and 11 blue berries in the second shrub then Phoenix can fill 22 baskets of capacity 44 completely:

  • the first basket will contain 33 red and 11 blue berries from the first shrub;
  • the second basket will contain the 22 remaining red berries from the first shrub and 22 red berries from the second shrub.

Help Phoenix determine the maximum number of baskets he can fill completely!

凤凰正在自家后院采摘浆果。一共有 nn 丛灌木,第 ii 丛灌木上有 aia_i 颗红浆果和 bib_i 颗蓝浆果。

每个篮子可装 kk 颗浆果。但凤凰规定:每个篮子中所装的浆果必须全部来自同一丛灌木,或全部为同一种颜色(红色或蓝色)。换言之,篮子中所有浆果必须满足“同丛”或“同色”(或同时满足两者)。

例如,假设有两丛灌木:第一丛有 55 颗红浆果和 22 颗蓝浆果,第二丛有 22 颗红浆果和 11 颗蓝浆果。那么凤凰可以恰好装满 22 个容量为 44 的篮子:

  • 第一个篮子装来自第一丛的 33 颗红浆果和 11 颗蓝浆果;
  • 第二个篮子装来自第一丛剩余的 22 颗红浆果,以及来自第二丛的 22 颗红浆果。

请帮助凤凰计算他最多能恰好装满多少个篮子!

输入格式

The first line contains two integers nn and kk ($ 1\le n, k \le 500$) — the number of shrubs and the basket capacity, respectively.

The ii-th of the next nn lines contain two integers aia_i and bib_i (0≤ai,bi≤1090 \le a_i, b_i \le 10^9) — the number of red and blue berries in the ii-th shrub, respectively.

第一行包含两个整数 nn 和 kk(1≤n,k≤5001\le n, k \le 500),分别表示灌木丛的数量和篮子的容量。

接下来的 nn 行中,第 ii 行包含两个整数 aia_i 和 bib_i(0≤ai,bi≤1090 \le a_i, b_i \le 10^9),分别表示第 ii 棵灌木丛中红莓和蓝莓的数量。

输出格式

Output one integer — the maximum number of baskets that Phoenix can fill completely.

输出一个整数——Phoenix 最多能完全装满的篮子数量。

输入输出样例

  • 输入#1

    2 4
    5 2
    2 1

    输出#1

    2
  • 输入#2

    1 5
    2 3

    输出#2

    1
  • 输入#3

    2 5
    2 1
    1 3

    输出#3

    0
  • 输入#4

    1 2
    1000000000 1

    输出#4

    500000000

说明/提示

The first example is described above.

In the second example, Phoenix can fill one basket fully using all the berries from the first (and only) shrub.

In the third example, Phoenix cannot fill any basket completely because there are less than 55 berries in each shrub, less than 55 total red berries, and less than 55 total blue berries.

In the fourth example, Phoenix can put all the red berries into baskets, leaving an extra blue berry behind.

第一个示例已在上文描述。

在第二个示例中,凤凰可以利用第一株(也是唯一一株)灌木上的全部浆果,将一个篮子装满。

在第三个示例中,凤凰无法完全装满任何一个篮子,因为每株灌木的浆果数量均少于 55 颗,红色浆果总数少于 55 颗,蓝色浆果总数也少于 55 颗。

在第四个示例中,凤凰可以将所有红色浆果放入篮子中,剩余一颗蓝色浆果未被放入。

输入解题思路,AI测评打分。不知道怎么写?

首页