Description

A set of frogs have accidentally fallen to the bottom of a large pit. Their only means of escaping the pit is to jump out of it. Each frog i​ is described by three parameters (li, wi, hi)​ where li​ is its leap capacity, wi​ its weight, and hi​ its height. The leap capacity specifies how high that frog can jump. If a frog's leap capacity is strictly larger than the depth of the pit, the frog can directly escape the pit. However, these frogs are altruistic. Rather than selfishly saving themselves and leaving the frogs with too limited leap capacity behind, they collectively aim to save as many of them from the pit as possible.

The frogs realize that if a frog A​ climbs up on the back of frog B​ before it jumps, the first frog A​ stands a better chance of escaping the pit: it can escape if hB + lA​ is strictly larger than the depth of the pit.

Furthermore, if frog B carrying frog A on its back climbs up on the back of frog C, the situation is even better for frog A: it can now escape the pit if hC + hB + lA is strictly larger than the depth of the pit.

The frogs can build even higher piles of frogs this way, the only restriction is that no frog may carry other frogs of weight in total amounting to its own weight or heavier. Once a pile has been used to allow a frog to escape, the frogs in the pile jump back to the bottom of the pit and they can then form a new pile (possibly consisting of a different set of frogs). The question is simply how many frogs can escape the pit assuming they collaborate to maximize this number?

Input

The first line of input contains two integers n​ and d​ (1 ≤ n ≤ 100 000​, 1 ≤ d ≤ 108​), where n​ is the number of frogs and d​ is the depth of the pit in µm. Then follow n​ lines each containing three integers l, w, h​ (1 ≤ l, w, h ≤ 108​), representing a frog with leap capacity l​ µm, weight w​ µg, and height h​ µm. The sum of all frogs' weights is at most 108​ µg.

Output

Output the maximum number of frogs that can escape the pit.

Sample Input

3 19
15 5 3
12 4 4
20 10 5

Sample Output

3

Hint

Source

ncpc2018

这个就是一个01背包,好难看出来啊,开始我以为是贪心,昨天的一个状压dp我也以为是贪心,

所以呢,如果我觉得像贪心但是又不能肯定的,那应该是dp

代码要是看不懂,那就模拟一次就会了

#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <iostream>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int mx = 1e5 + ;
struct node
{
int l, w, h;
}exa[mx]; bool cmp(node a,node b)
{
return a.w > b.w;
}
const int maxn = 1e8 + ;
int dp[maxn]; int main()
{
int n, d;
cin >> n >> d;
for(int i=;i<n;i++)
{
cin >> exa[i].l >> exa[i].w >> exa[i].h;
}
int ans = ;
sort(exa , exa + n, cmp);
for(int i=;i<n;i++)
{
int w = exa[i].w;
if (exa[i].l + dp[w] > d) ans++;
for(int j=;j<min(w,maxn-w);j++)
{
dp[j] = max(dp[j], dp[j + w] + exa[i].h);
}
}
cout << ans << endl;
return ;
}

最新文章

  1. (十一)WebGIS中要素(Feature)的设计
  2. Ext5实现树形下拉框ComboBoxTree
  3. SQL-truncate &amp;&amp; delete &amp;&amp; drop 的区别
  4. python之打包相关
  5. 公共数据访问对象接口CommDao
  6. .NET Nancy 详解(四) Self Host
  7. ztree check
  8. HTTP请求错误大全
  9. 收集一下Windows7系统啊
  10. 绑定本地Service并与之通信
  11. c++中双冒号的作用
  12. ClientDataSet应用
  13. day11-元组与字典
  14. 高强度减脂Tabata练习
  15. python 判断字符串中字符类型的常用方法
  16. bzoj1825: [JSOI2010]蔬菜庆典
  17. android权限permission大全(权限提醒)
  18. 有 a - b &lt; c 对Java安全性的思考
  19. 框架----Django框架(基础篇)
  20. 问题 H: 抽奖活动(大数)

热门文章

  1. 小程序wepy2 模拟vant PasswordInput, NumberKeyboard 密码输入框控件
  2. 如何使用Swagger-UI在线生成漂亮的接口文档
  3. 如何提高你使用windows的逼格(windows用成Linux的赶脚)
  4. undefined 和 not defined
  5. [转] Roguelike开发建议
  6. 常见的Web源码泄漏漏洞及其利用
  7. Springboot:静态资源加载(七)
  8. 小白初学Java的一点点收获
  9. MySQL中出现Unknow column &#39;xx&#39; in field list的解决办法
  10. Caused by: java.io.IOException: Type mismath in vlaue from map: excepted org.apache.hadoop.io.InaWritable,received SC