E. Fire
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

此题虽然A了;

但是感觉自己的做法还是有点问题的;

将这个(x,y,z)这个三元组以y排序;

做一遍背包就行了;

时间复杂度为O(2000*100*100);

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;

][],num,maxx,pos,sum,ans[];
struct node{
    int t,d,p,pos;
}f[];

bool cmp(node a,node b){
    if(a.d==b.d){
        a.p<b.p;
    }
    return a.d<b.d;
}

int main(){
    scanf("%d",&n);
    num=;
    ;i<=n;i++){
        scanf("%d%d%d",&f[i].t,&f[i].d,&f[i].p);
        f[i].pos=i;
        f[i].d--;
        num=max(num,f[i].d);
    }
    sort(f+,f+n+,cmp);
    memset(dp,-,sizeof(dp));
    dp[][]=;
    ;i<=n;i++){
        for(int j=f[i].d;j>=f[i].t;j--){
            ]!=-&&dp[j-f[i].t][]+f[i].p>=dp[j][]){
                ;k<=n;k++)
                    dp[j][k]=dp[j-f[i].t][k];
                dp[j][]=dp[j][]+f[i].p;
                dp[j][i]=;
            }
        }
    }
    maxx=; pos=;
    ;i<=num;i++)
        ]>maxx) maxx=dp[i][],pos=i;
    printf("%d\n",maxx);
    ;i<=n;i++)
    ){
        sum++;
        ans[sum]=f[i].pos;
    }
    printf("%d\n",sum);
    ;i<sum;i++)
        printf("%d ",ans[i]);
    printf("%d",ans[sum]);
}

Codeforce E. Fire的更多相关文章

  1. codeforce 35C fire again

    2017-08-25 17:04:07 writer:pprp 题目描述: • Codeforces 35C Fire Again• N*M的格子,最开始有K个点 (坐标给定) 开始着火• 每一秒着火 ...

  2. codeforce E. Fire背包

    E. Fire time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  3. 关于SequeezeNet中的Fire Module

    在论文<SQUEEZENET: ALEXNET-LEVEL ACCURACY WITH 50X FEWER PARAMETERS AND <0.5MB MODEL SIZE>中,作者 ...

  4. FZU 2150 Fire Game

    Fire Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

  5. Fire

    Fire 分析: 首先,明确题意:b1,b2,--,bn 交换为b2,--,bn,b1,但这并不是意味着只能从b1开始交换,(这点从样例中可以看出),并且也不意味着交换的必须是连续的一串,可以是几个单 ...

  6. Android 轻量级输入校验库:Fire Eye

    Fire Eye是一款轻量级简单易用的Android校验库. FireEye 2.0 在 1.0 的基础上,全部重写了代码,并优化了架构,性能上和逻辑上都大大提升.只需要几行代码,即可验证用户输入,并 ...

  7. ACM: FZU 2150 Fire Game - DFS+BFS+枝剪 或者 纯BFS+枝剪

    FZU 2150 Fire Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  8. Codeforce - Street Lamps

    Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...

  9. UVA 11624 Fire!(广度优先搜索)

    题目大意:在一个N*M的迷宫内,J代表某人(只有一个),F代表火(可能不只一个),#代表墙,火每分钟会向四周除了墙以外的地方扩散一层,问人能否在没被火烧到 之前逃出迷宫,若能逃出输出最短时间.很明显的 ...

随机推荐

  1. oracle之备份详解

    1.冷备份(执行冷备份前必须关闭数据库) 物理备份(备份物理数据库文件) 2.热备份(热备份是当数据库正在运行时进行数据备份的过程.执行热备份的前提是:数据库运行在可归档日志模式.适用于24X7不间断 ...

  2. WIN7+IE8环境QTP11不能录制和识别web对象的解决方法

    在项目稍微空闲的时间,在办公电脑上面装上QTP11来学习.但是发现在录制脚本时无法录制web对象,在网上找解决方法说以管理员的身份运行QTP就可以解决无法录制的问题,用这方法证明是ok的.后来用Obj ...

  3. Java内存模型_基础

    线程之间的通信机制有两种: 1.共享内存:线程之间共享程序的公共状态,通过写-读内存中的公共状态进行隐式的通信. 2.消息传递:线程之间没有公共状态,线程之间必须发送消息来显示的进行通信 同步:是指程 ...

  4. 16汇编第十讲完结Call变为函数以及指令的最后讲解

    16汇编完结Call变为函数以及指令的最后讲解 学了10天的16位汇编,这一讲就结束了,这里总结一下昨天的LOOP指令的缺陷,因为lOOP指令的缺陷,所以我们都改为下面的汇编代码使用了,自己去写,其中 ...

  5. Akka(23): Stream:自定义流构件功能-Custom defined stream processing stages

    从总体上看:akka-stream是由数据源头Source,流通节点Flow和数据流终点Sink三个框架性的流构件(stream components)组成的.这其中:Source和Sink是stre ...

  6. [ASP.NET MVC]笔记(四 UnobtruSive AJAX和客户端验证

    UnobtruSive AJAX和客户端验证 ASP.NET MVC 已经默认开启非侵入试js和客户端验证,在web.config可以看到如下配置: <configuration> < ...

  7. javaScript数组去重方法

    在JAvascript平时项目开发中经常会用到数组去重的操作.这时候就要用到JS数组去重的方法了. demo1: 第一种:JS数组去重操作方法是利用遍历原数组,利用数组的indexOf()方法来来判断 ...

  8. JavaScript: 使用 atan2 来绘制 箭头 和 曲线

    最近搞Canvas绘图,知道了JavaScript中提供了atan2(y,x)这样一个三角函数.乍眼一看,不认识,毕竟在高中时,学过的三角函数有:sin,cos,arcsin,arccos,tan,a ...

  9. 使用JavaScript循环嵌套解决各种图形

    [循环嵌套的规律]    1.外层循环控制行数,内层循环控制每行中元素的个数. [图形题思路]    1.确定图形有几行,行数即为外层循环次数:    2.确定每行中有几种元素组成,有几种元素表示有几 ...

  10. 201521123005 《java程序设计》 第八周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 2. 书面作业 本次作业题集集合 Q1List中指定元素的删除(题目4 ...