CF1348E.Phoenix and Berries

普及/提高-

通过率:0%

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!

输入格式

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 ( 0ai,bi1090 \le a_i, b_i \le 10^9 ) — the number of red and blue berries in the ii -th shrub, respectively.

输出格式

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

输入输出样例

  • 输入#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.

首页