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. 《APP开发》APP规范实例-详细的UI设计方法

    对了一个APP开发初手来说,可能心里有很多的疑惑: 屏幕设计为多宽,宽度是不是应该设置为百分比; 按钮大小多大,怎么排列,文字字体用多大的?什么字体显示好看?图标多大,怎么用色?界面怎么布局?等等很多 ...

  2. HDU 1041

    题意: 给原始序列1 给定变化规则是,对于原来的序列每一个0前边插入1,每个1前边插入0. 问原始序列经过n次变化之后有多少对相邻的0. 规律题: 从第二次开始 当第奇数次变化之后,数量变成原来数量的 ...

  3. Md5扩展攻击的原理和应用

    *本文原创作者:Guilty and Innocent,本文属FreeBuf原创奖励计划,未经许可禁止转载 做CTF题目的过程中遇到了md5扩展攻击,参考了几篇文章,感觉写的都有些小缺陷,再发一篇文章 ...

  4. ECC数据结构

    在SM2 ECC算法中,有针对签名加密的数据结构,下面对这些结构进行分析 #define ECCref_MAX_BITS 512 #define ECCref_MAX_LEN ((ECCref_MAX ...

  5. 【Facebook的UI开发框架React入门之八】Image的使用简单介绍(iOS平台)-goodmao

    --------------------------------------------------------------------------------------------------- ...

  6. woodcut

    http://www.lintcode.com/en/problem/wood-cut/# 二分答案,贪心验证,具有单调性 class Solution { public: /** *@param L ...

  7. Android开发文档翻译之-Services

    Service是一种能长期在后台运行同一时候不须要与用户进行交互的应用组件.其它组件能够开启service,开启后service能够自行运行及时用户已经切换到其它的应用.此外,组件能够与service ...

  8. 6 JobApp默认视图开发

    第一步:引入angularjs 添加app模块 现在我们正式进入开发,下面是我们在上一节建立的目录结构: 我们需要再src路径下,新建index.html文件,先引入angularjs文件: < ...

  9. 刚刚做了个文件上传功能,拿来分享一下!(MVC架构及传统架构通用)

    文件上传无论在软件还是在网站上都十分常见,我今天再把它拿出来,讲一下,主要讲一下它的设计思想和实现技术,为了它的通用性,我把它做在了WEB.Service项目里,即它是针对服务器的,它的结构是关联UI ...

  10. ubuntu安装jdk 1.6

    linux下安装JDK1.6 1. 去http://java.sun.com/j2se/1.4.2/download.html 下载一个Linux Platform的JDK,建议下载RPM自解压格式的 ...