A13395 | Phoenix and Berries
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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!
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!
输入格式
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.
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 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 $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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted