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 tiseconds 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 2seconds. 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 3seconds, but this item will already be completely burned by this time.

————————————————————————————

这道题其实就是有人家着火了 一个物品有三个属性 营救所需要的时间ti 必须在di前被救(注意是前) 价值为 pi

要求输出最多能救的最大价值 并输出方案 即营救了多少物品 并输出这些物品 (按营救顺序

这样之后呢 我们发现最大价值其实可以背包 而背包的方案输出可以用一个数组记一下转移顺序就可以了

#include<cstdio>
#include<cstring>
#include<algorithm>
using std::max;
using std::sort;
const int M=;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
int n,f[M][],map[M][];
struct pos{int t,d,p,id;}q[M];
bool cmp(pos a,pos b){return a.d<b.d;}
int qu[M],cnt;
int mx=,id;
int main(){
n=read();
for(int i=;i<=n;i++) q[i].t=read(),q[i].d=read()-,q[i].p=read(),q[i].id=i;
std::sort(q+,q++n,cmp);
for(int i=;i<=n;i++){
for(int j=q[i].d;j>=q[i].t;j--){
if(f[i-][j-q[i].t]+q[i].p>f[i-][j]){
f[i][j]=f[i-][j-q[i].t]+q[i].p;
map[i][j]=j-q[i].t;
}
else{f[i][j]=f[i-][j]; map[i][j]=j;}
}
for(int j=q[i].t-;j;j--) f[i][j]=f[i-][j],map[i][j]=j;
}
for(int j=;j<=q[n].d;j++) if(f[n][j]>mx) mx=f[n][j],id=j;
printf("%d\n",mx);
int l=n,r=id;
for (int i=n;i>=;i--){
if (map[i][r]<r) qu[++cnt]=q[i].id;
r=map[i][r];
}
printf("%d\n",cnt);
for(int i=cnt;i;i--) printf("%d ",qu[i]);
return ;
}

codeforces——contest 864 problemE的更多相关文章

  1. codeforces contest 864 problemD

    Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to n. Recently ...

  2. [codeforces contest 1119 F] Niyaz and Small Degrees 解题报告 (树形DP+堆)

    interlinkage: http://codeforces.com/contest/1119/problem/F description: 有一颗$n$个节点的树,每条边有一个边权 对于一个$x$ ...

  3. CodeForces contest/776 A+B+C题解

    ICM Technex 2017 and Codeforces Round #400 (Div. 1 +Div.2,combined) A. A Serial Killer 谜一样的题意:每天从两个人 ...

  4. codeforces/contest/803/problem C

    题目:C. Maximal GCD 题意:输入n,k.将n拆成k个数的序列,使得这k个数的gcd最大.(且序列严格递增).1 ≤ n, k ≤ 1010 . 分析:假设k个数的gcd为d,则一定有d| ...

  5. 【codeforces contest 1119 F】Niyaz and Small Degrees

    题目 描述 \(n\) 个点的树,每条边有一个边权: 对于一个 \(X\) ,求删去一些边后使得每个点的度数 \(d_i\) 均不超过 \(X\) 的最小代价: 你需要依次输出 \(X=0 \to n ...

  6. CodeForces Contest #1137: Round #545 (Div. 1)

    比赛传送门:CF #1137. 比赛记录:点我. 每次都自闭的 div1 啊,什么时候才能上 IM 呢. [A]Skyscrapers 题意简述: 有一个 \(n\times m\) 的矩阵 \(a_ ...

  7. CodeForces Contest #1114: Round #538 (Div. 2)

    比赛传送门:CF #1114. 比赛记录:点我. 又 FST 了. [A]Got Any Grapes? 题意简述: 有三个人,第一个人需要吃绿色葡萄至少 \(a\) 个,第二个人需要吃绿色和紫色葡萄 ...

  8. CodeForces Contest #1110: Global Round 1

    比赛传送门:CF #1110. 比赛记录:点我. 涨了挺多分,希望下次还能涨. [A]Parity 题意简述: 问 \(k\) 位 \(b\) 进制数 \(\overline{a_1a_2\cdots ...

  9. codeforces contest 1111

    A. Superhero Transformation 题意: 元音和元音,辅音和辅音字母之间可以互相转换,问两个字符串是否想同: 题解:直接判断即可: #include<bits/stdc++ ...

随机推荐

  1. A4

    队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 很胖,刚学,照猫画虎做了登录与注册界面. 展示GitHub ...

  2. 哈希表 STL map

    计数排序时我们使用一个数组来记录出现的数字的次数,而当数据范围太大时,无法建立一个那么大地数组(而且可能空间利用率很低,太浪费),此时可以改用hash table . binary search tr ...

  3. Java容器之Iterator接口

    Iterator 接口: 1. 所有实现了Collection接口的容器类都有一个iterator方法用以返回一个实现了Iterator接口的对象. 2. Iterator 对象称作迭代器,用以方便的 ...

  4. CEntOS6.5从启动界面直接进入命令行界面

    ctrl + alt + F1 ctrl + alt + F2 ctrl + alt + F3 ctrl + alt + F4 ctrl + alt + F5 ctrl + alt + F6 同时按下 ...

  5. windows与linux下执行.class(包含main方法)

    来源:http://blog.csdn.net/hanqunfeng/article/details/4327325 一般来说,执行一个java文件采用执行jar包的方式最为方便(java -jar ...

  6. 【BZOJ1941】Hide and Seek(KD-Tree)

    [BZOJ1941]Hide and Seek(KD-Tree) 题面 BZOJ 洛谷 题解 \(KD-Tree\)对于每个点搜一下最近点和最远点就好了 #include<iostream> ...

  7. sd卡的访问

    一般再访问sd卡前都要获取sd卡的路径,以防止不同的厂商有不同的路径配置.Android提供了Environment类来获取系统当前sd卡路径. Log.d(TAG, Environment.getE ...

  8. 牛客网 Wannafly挑战赛27 蓝魔法师

    蓝魔法师 链接: https://www.nowcoder.com/acm/contest/215/C 来源:牛客网 题目描述 "你,你认错人了.我真的,真的不是食人魔."--蓝魔 ...

  9. UVA.136 Ugly Numbers (优先队列)

    UVA.136 Ugly Numbers (优先队列) 题意分析 如果一个数字是2,3,5的倍数,那么他就叫做丑数,规定1也是丑数,现在求解第1500个丑数是多少. 既然某数字2,3,5倍均是丑数,且 ...

  10. UVA.10192 Vacation (DP LCS)

    UVA.10192 Vacation (DP LCS) 题意分析 某人要指定旅游路线,父母分别给出了一系列城市的旅游顺序,求满足父母建议的最大的城市数量是多少. 对于父母的建议分别作为2个子串,对其做 ...