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. pointer-events的css属性。使用该属性可以决定是否能穿透绝对定位元素去触发下面元素的某些行为

    pointer-events的css属性.使用该属性可以决定是否能穿透绝对定位元素去触发下面元素的某些行为,比如当一个元素盖住了某个点击事件时可用. 现在Firefox3.6+/Safari4+/Ch ...

  2. python如何命令行下载包

    $ wget https://bootstrap.pypa.io/get-pip.py $ python get-pip.py $ pip -V #查看pip版本     $ pip install ...

  3. 【BZOJ 1212】[HNOI2004]L语言

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 因为查询的字典里面.单词的最大长度为10 所以. 如果建立一棵字典树的话. 深度最多为10: 那么可以写一个DP; 设f[i]表示1 ...

  4. 【图灵杯 A】谷神的赌博游戏

    [题目链接]:http://oj.acmclub.cn/problem.php?cid=1164&pid=0 [题意] [题解] 把每个数字都%3处理; 会发现最后1的个数为n+1 2和0的个 ...

  5. 4、python序列对比

    1.列表:[ ],杂(什么都可以放进去),有序,可变 2.元组:(),有序,不可变 3.字典:{ },键值对,无序,可变 4.集合:{ },不可重复,无序,可变

  6. 2015-8-29阿里校园招聘研发project师笔试题

    前言:原题来自于网络:http://www.cnblogs.com/nausicaa/p/3946694.html.本人依据自己理解对题目进行解答.因为水平有限.题目有不会做.做错的地方.欢迎大家留言 ...

  7. poj_3468,线段树成段更新

    参考自http://www.notonlysuccess.com/index.php/segment-tree-complete/ #include<iostream> #include& ...

  8. Android Button 按钮 设置 各种状态 图片 颜色

    有2个方法可以实现,一种是用 选择器 定义每种状态的图片 selec.xml <?xml version="1.0" encoding="utf-8"?& ...

  9. Tomcat下没有编译后的class文件

    输出的路径是否正确: Default output folder: 如果tomcat下还没有classes文件则没有编译好 需要重新引入jar包, clean工程,并重新部署项目. 这样就会在tomc ...

  10. manacherO(n)求最长回文子串 hihocoder1032

    原文地址:https://segmentfault.com/a/1190000003914228   http://blog.csdn.net/synapse7/article/details/189 ...