CodeForces_1348E Phoenix and Berries(动态规划)

Phoenix and Berries

time limit per test:2 seconds
memory limit per test:256 megabytes
Problem Description

Phoenix is picking berries in his backyard. There are n shrubs, and each shrub has ai red berries and bi 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 ≤ n , k ≤ 500 1≤n,k≤500 1n,k500) — the number of shrubs and the basket capacity, respectively.

The i-th of the next n lines contain two integers a i a_i ai and b i b_i bi ( 0 ≤ a i , b i ≤ 1 0 9 0≤a_i,b_i≤10^9 0ai,bi109) — 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.

Sample Input

2 4
5 2
2 1

Sample Output

2

题意

n棵树,每棵树上有ai个红果实和bi个蓝果实。有可以装k个果实的篮子,一个篮子只能放同种颜色或同一棵树上的果实。求最多可以放满多少个篮子?

题解

显然大多数篮子内的果实都是同颜色的,最多只有n个篮子内的果实是不同色的(若同棵树有多个篮子装的不同色果实,可以将其转为为多个同色篮和一个不同色)。所以只需要考虑每棵树不同颜色的那个篮子的组成。
d p [ i ] [ j ] dp[i][j] dp</

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值