Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take ti seconds to save i-th item. In addition, for each item, he estimated the value of di — the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if ti ≥ di, then i-th item cannot be saved.

Given the values pi for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the item a will be saved in ta seconds, and the item b — in ta + tb seconds after fire started.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of items in Polycarp's house.

Each of the following n lines contains three integers ti, di, pi (1 ≤ ti ≤ 20, 1 ≤ di ≤ 2 000, 1 ≤ pi ≤ 20) — the time needed to save the item i, the time after which the item i will burn completely and the value of item i.

Output

In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m — the number of items in the desired set. In the third line print m distinct integers — numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them.

Examples
Input
3
3 7 4
2 6 5
3 7 6
Output
11
2
2 3
Input
2
5 6 1
3 3 5
Output
1
1
1
Note

In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11.

In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.

01背包多了一个控制条件,还有题目要求打印任意一种,但必须按照顺序(不是字典序),因此需要对d排序了。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/sTACK:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
struct point
{
int t;
int d;
int p;
int id;
friend bool operator<(const point &a,const point &b)
{
return a.d<b.d;
}
}e[];
int n,x,y,z,k=;
int dp[];
int path[][];
int vis[];
int main()
{
scanf("%d",&n);
int pos=;
for(int i=;i<=n;i++)
{
scanf("%d%d%d",&x,&y,&z);
if(x>=y) continue;
e[++k].t=x;
e[k].d=y;
e[k].p=z;
e[k].id=i;
pos=max(pos,y);
}
sort(e+,e+k+);
memset(dp,,sizeof(dp));
memset(path,,sizeof(path));
for(int i=;i<=k;i++)
{
for(int j=e[i].d-;j>=e[i].t;j--)
{
if(dp[j]<(dp[j-e[i].t]+e[i].p))//中间变量注意边界。
{
dp[j]=dp[j-e[i].t]+e[i].p;
path[i][j]=;
}
}
}
int ans=-,cnt=;
for(int i=;i<=pos;i++)
{
ans=max(ans,dp[i]);
}
for(int j=pos;j>=;j--)
{
if(dp[j]==ans)
{
for(int i=k,s=j;i>= && s>=;i--)
{
if(path[i][s])
{
vis[cnt++]=e[i].id;
s-=e[i].t;
}
}
break;
}
}
reverse(vis,vis+cnt);
printf("%d\n%d\n",ans,cnt);
for(int i=;i<cnt;i++)
{
if(i) printf(" ");
printf("%d",vis[i]);
}
return ;
}

Coderfroces 864 E. Fire(01背包+路径标记)的更多相关文章

  1. UVA 624 ---CD 01背包路径输出

    DescriptionCD You have a long drive by car ahead. You have a tape recorder, but unfortunately your b ...

  2. UVA 624 CD【01背包+路径记录】

    You have a long drive by car ahead. You have a tape recorder, but unfortunately your best music is o ...

  3. UVA--624 CD(01背包+路径输出)

    题目http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. Happy Programming Contest(ZOJ3703)(01背包+路径储存)

    Happy Programming Contest  ZOJ3703 老实说:题目意思没看懂...(希望路过的大神指点) 最后那个the total penalty time是什么意思啊!!! 还是学 ...

  5. uva624 CD (01背包+路径的输出)

    CD Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Practice UVA 624 ...

  6. HDU 6083 度度熊的午饭时光(01背包+记录路径)

    http://acm.hdu.edu.cn/showproblem.php?pid=6083 题意: 思路: 01背包+路径记录. 题目有点坑,我一开始逆序枚举菜品,然后一直WA,可能这样的话路径记录 ...

  7. UVA624 CD,01背包+打印路径,好题!

    624 - CD 题意:一段n分钟的路程,磁带里有m首歌,每首歌有一个时间,求最多能听多少分钟的歌,并求出是拿几首歌. 思路:如果是求时常,直接用01背包即可,但设计到打印路径这里就用一个二维数组标记 ...

  8. 牛客网暑期ACM多校训练营(第三场) A PACM Team 01背包 记录路径

    链接:https://www.nowcoder.com/acm/contest/141/A来源:牛客网 Eddy was a contestant participating in ACM ICPC ...

  9. 01背包记录路径 (例题 L3-001 凑零钱 (30分))

    题意: 就是找出来一个字典序最小的硬币集合,且这个硬币集合里面所有硬币的值的和等于题目中的M 题解: 01背包加一下记录路径,如果1硬币不止一个,那我们也不采用多重背包的方式,把每一个1硬币当成一个独 ...

随机推荐

  1. 2015,鬼王Xun和GGL比赛,带给我们无尽的欢乐

    一如既往的风格,正文之前,先扯蛋~     这篇文章好久就想写了,一直没有动笔,最近在忙于Android和iOS等技术研究,又忙于金融投资等方面的学习和写作.这个周末,把技术进度延缓了点,把很多闲杂的 ...

  2. 洛谷 P2818 天使的起誓

    P2818 天使的起誓 题目描述 Tenshi非常幸运地被选为掌管智慧之匙的天使.在正式任职之前,她必须和其他新当选的天使一样要宣誓.宣誓仪式是每位天使各自表述自己的使命,他们的发言稿放在n个呈圆形排 ...

  3. Android 手机影音 开发过程记录(六)

    前一篇已经将音乐播放及切换的相关逻辑弄好了,今天主要理一下剩余的部分,包含: 1. 自己定义通知栏的布局及逻辑处理 2. 滚动歌词的绘制 3. 歌词解析 效果图 通知栏 自己定义布局: <?xm ...

  4. 12、NIO、AIO、BIO二

    一.NIO2快速读写文件 写完之后记得flush一下,NIO2不能自行创建文件,需要在文件中判断一下. package com.zxc.L; import org.junit.Test; import ...

  5. taglist安装

    注意:taglist依赖于ctags,所以要先装ctags,否则taglist装了也没法用!1.首先安装ctags1)ubuntu安装sudo apt-get install exuberant-ct ...

  6. BZOJ1468: Tree & BZOJ3365: [Usaco2004 Feb]Distance Statistics 路程统计

    [传送门:BZOJ1468&BZOJ3365] 简要题意: 给出一棵n个点的树,和每条边的边权,求出有多少个点对的距离<=k 题解: 点分治模板题 点分治的主要步骤: 1.首先选取一个点 ...

  7. Traversal with a for loop

    A lot of computations involve processing a string one character at a time. Often they start at the b ...

  8. 8.queue

    #include <iostream> #include <stack> #include <algorithm> #include <list> #i ...

  9. package & import

    /* * package:声明源文件所在的包,写在程序的第一行. * 每“.”一次,表示一层文件目录. * 包名都要小写. * * import: * 1)显式导入指定包下的类或接口 * 2)写在包的 ...

  10. Spring MVC 核心架构图

    架构图对应的DispatcherServlet核心代码如下: //前端控制器分派方法 protected void doDispatch(HttpServletRequest request, Htt ...