Codeforces Round 638 (Div. 2)
E
Phoenix and Berries
Codeforces
2400
原题
← DF →
翻译中…

Phoenix is picking berries in his backyard. There are $n$ shrubs, and each shrub has $a_i$ red berries and $b_i$ blue berries.

翻译中…

Each basket can contain $k$ 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 $5$ red and $2$ blue berries in the first shrub and $2$ red and $1$ blue berries in the second shrub then Phoenix can fill $2$ baskets of capacity $4$ completely:

翻译中…
  • the first basket will contain $3$ red and $1$ blue berries from the first shrub;
  • the second basket will contain the $2$ remaining red berries from the first shrub and $2$ red berries from the second shrub.
翻译中…

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

翻译中…

Input

翻译中…

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

翻译中…

The $i$-th of the next $n$ lines contain two integers $a_i$ and $b_i$ ($0 \le a_i, b_i \le 10^9$) — the number of red and blue berries in the $i$-th shrub, respectively.

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

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 $5$ berries in each shrub, less than $5$ total red berries, and less than $5$ total blue berries.

翻译中…

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

翻译中…

样例

Input #1
2 4
5 2
2 1
Output #1
2
InputCopy OutputCopy
Input #2
1 5
2 3
Output #2
1
InputCopy OutputCopy
Input #3
2 5
2 1
1 3
Output #3
0
InputCopy OutputCopy
Input #4
1 2
1000000000 1
Output #4
500000000
InputCopy OutputCopy
题目信息
题号
1348E
时间限制
2 s
内存限制
256 MB
标签
暴力
动态规划
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。