D. Don't fear, DravDe is kind
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

A motorcade of n trucks, driving from city «Z» to city «З», has approached a tunnel, known as Tunnel of Horror. Among truck drivers there were rumours about monster DravDe, who hunts for drivers in that tunnel. Some drivers fear to go first, others - to be the last, but let's consider the general case. Each truck is described with four numbers:

  • v — value of the truck, of its passangers and cargo
  • c — amount of passanger on the truck, the driver included
  • l — total amount of people that should go into the tunnel before this truck, so that the driver can overcome his fear («if the monster appears in front of the motorcade, he'll eat them first»)
  • r — total amount of people that should follow this truck, so that the driver can overcome his fear («if the monster appears behind the motorcade, he'll eat them first»).

Since the road is narrow, it's impossible to escape DravDe, if he appears from one side. Moreover, the motorcade can't be rearranged. The order of the trucks can't be changed, but it's possible to take any truck out of the motorcade, and leave it near the tunnel for an indefinite period. You, as the head of the motorcade, should remove some of the trucks so, that the rest of the motorcade can move into the tunnel and the total amount of the left trucks' values is maximal.

Input

The first input line contains integer number n (1 ≤ n ≤ 105) — amount of trucks in the motorcade. The following n lines contain four integers each. Numbers in the i-th line: vi, ci, li, ri (1 ≤ vi ≤ 104, 1 ≤ ci ≤ 105, 0 ≤ li, ri ≤ 105) — describe the i-th truck. The trucks are numbered from 1, counting from the front of the motorcade.

Output

In the first line output number k — amount of trucks that will drive into the tunnel. In the second line output k numbers — indexes of these trucks in ascending order. Don't forget please that you are not allowed to change the order of trucks. If the answer is not unique, output any.

Examples
input

Copy
5
1 1 0 3
1 1 1 2
1 1 2 1
1 1 3 0
2 1 3 0
output

Copy
4
1 2 3 5
input

Copy
5
1 1 0 3
10 1 2 1
2 2 1 1
10 1 1 2
3 1 3 0
output

Copy
3
1 3 5
/*
这道题.....雾......
就是按l+r+c分类嘛....
可是...但可是....可但是.....
算了,copycopygiveup.....
*/ #include<bits/stdc++.h> using namespace std;
const int Inf=1e9;
struct truck
{
int v,c,l,id,sum;
truck(int v,int c,int l,int id) : id(id), v(v), c(c), l(l) {}
};
vector<truck> t[];
map<int,pair<int,int> > mp;
vector<int> ans;
int Nxt[];
int n;
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
int v,c,l,r ;
scanf("%d%d%d%d",&v,&c,&l,&r);
t[c+l+r].push_back(truck(v,c,l,i));
}
int res=;
ans.clear();
for(int s=; s<; s++) //枚举c+l+r的长度
{
if(t[s].size())
{
mp.clear();
int len=t[s].size();
mp[s]=make_pair(,Inf);
for(int i=len-; i>=; i--)
{
int l=t[s][i].l;
int c=t[s][i].c;
int v=t[s][i].v;
int cnt=l+c;
if(mp.find(cnt)==mp.end()) continue;
int val=v+mp[cnt].first; //mp存储dp结果
Nxt[i]=mp[cnt].second;
if(mp[l].first<val)
{
mp[l]=make_pair(val,i); //人数值对应最大价值和当前vector中的编号
}
}
if(res<mp[].first)
{
res=mp[].first;
ans.clear();
for(int i=mp[].second; i<Inf/; i=Nxt[i])
{
ans.push_back(t[s][i].id);
}
}
}
}
printf("%d\n",ans.size());
for(int i=; i<ans.size(); i++)
{
printf("%d",ans[i]);
if(i!=ans.size()-)printf(" ");
}
return ;
}

codeforces 28D(dp)的更多相关文章

  1. CodeForces 28D Don&#39;t fear, DravDe is kind dp

    主题链接:点击打开链接 为了让球队后,删除是合法的.也就是说,对于每一个车辆, l+r+c 一样,按l+r+c分类. 然后dp一下. #include <cstdio> #include ...

  2. Two Melodies CodeForces - 813D (DP,技巧)

    https://codeforces.com/problemset/problem/813/D dp[i][j] = 一条链以i结尾, 另一条链以j结尾的最大值 关键要保证转移时两条链不能相交 #in ...

  3. Consecutive Subsequence CodeForces - 977F(dp)

    Consecutive Subsequence CodeForces - 977F 题目大意:输出一序列中的最大的连续数列的长度和与其对应的下标(连续是指 7 8 9这样的数列) 解题思路: 状态:把 ...

  4. codeforces的dp专题

    1.(467C)http://codeforces.com/problemset/problem/467/C 题意:有一个长为n的序列,选取k个长度为m的子序列(子序列中不能有位置重复),求所取的k个 ...

  5. Codeforces 721C [dp][拓扑排序]

    /* 题意:给你一个有向无环图.给一个限定t. 问从1点到n点,在不超过t的情况下,最多可以拜访几个点. 保证至少有一条路时限不超过t. 思路: 1.由无后向性我们可以知道(取决于该图是一个DAG), ...

  6. CodeForces 607C (DP) Hard problem

    题目:这里 题意:给定n个字符串,每个字符串可以进行一项操作,就是将这个字符串交换,就是该字符串的第一个和最后一个交换,第二个和倒数第二个交换,以此类推,当然可以选择对于 该字符串进行或不进行这项操作 ...

  7. Codeforces 611d [DP][字符串]

    /* 题意:给一个长度不超过5000的字符串,每个字符都是0到9的数字. 要求将整个字符串划分成严格递增的几个数字,并且不允许前导零. 思路: 1.很开心得发现,当我在前i个区间以后再加一个区间的时候 ...

  8. Codeforces 404D [DP]

    /* 我是一个习惯后悔,但是没办法忍受内疚感的二货== 这题是个无脑dp,但是比赛大概20min没出...其实最后5min我好好想想简单化边界条件,可以出的. 题意: 给你一个长度为1e6的由?*01 ...

  9. Codeforces 119C DP

    题意: 有n天,m门课和常数k; 每天上一门课,每门课程有两个属性,最少作业量a,最多作业量b,和难度c. 1<=a<=b<=1e16 c<=100 1<=n<=m ...

随机推荐

  1. 进入一个jsp直接跳到另一个jsp

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  2. USB多重系統 - 開機碟工具 – WinSetupFromUSB

    WinSetupFromUSB下載與安裝 讓USB磁碟擁有多重開機的功能,WinSetupFromUSB有著提軟體和硬體的高相容性. [官方網頁]:http://www.winsetupfromusb ...

  3. sqoop基本 操作

    列出 hive的 全部库 sqoop list-databases --connect jdbc:mysql://localhost --username hive --password hive 列 ...

  4. Zookeeper 简单操作

    1.  连接到zookeeper服务 [java2000_wl@localhost zookeeper-3]$ bin/zkCli.sh -server 127.0.0.1:2181 也可以连接远端的 ...

  5. 网络基础笔记——OSI七层模型

    OSI七层模型 由于整个网络连接的过程相当复杂,包含硬件.软件数据封包与应用程序的互相链接等等.假设想要写一支将联网所有功能都串连在一块的程序.那么当某个小环节出现故障时,整仅仅程序都须要改写.所以我 ...

  6. easyui使用心得

    一.搭建easyui运行环境 1.下载easyui压缩文件 2.将降压后的文件添加至webapp目录下 3.引用5个必须的js和css文件  <!--引入easyui样式文件--> < ...

  7. udhcp源码详解(三)上 之配置信息的读取

    上节介绍了存储管理配置信息的结构体struct server_config_t,该结构体贯穿整个server端程序的运行. 在dhcpd.c里的用该结构体定义个一个全局的变量: struct serv ...

  8. Python爬虫开发【第1篇】【Scrapy入门】

    Scrapy的安装介绍 Scrapy框架官方网址:http://doc.scrapy.org/en/latest Scrapy中文维护站点:http://scrapy-chs.readthedocs. ...

  9. 我要开启vue2新征程。

    最近我们Team接到一个新项目,给财务部开发一个内部用的结算系统. 我想了想,心里这个兴奋啊(内部系统诶,可以大胆一点的用vue2了...) 又多了一个能练手的项目,之前的卡爷就是太坑爹了...明明v ...

  10. android锁屏软件制作

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/mingyue_1128/article/details/33726515 转载请标明出处http:/ ...