CF28D.Don't fear, DravDe is kind

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

一支由 nn 辆卡车组成的车队正从「Z」市驶向「З」市,此时已抵达一条名为「恐怖隧道」的隧道。卡车司机们之间流传着一个关于怪物德拉弗德(DravDe)的传闻:他会在该隧道中猎杀司机。一些司机害怕排在最前面,另一些则害怕排在最后;但让我们考虑一般情况。每辆卡车用四个数字描述:

  • vv —— 卡车本身、其乘客及所载货物的价值;
  • cc —— 卡车上总人数(包括司机);
  • ll —— 在该卡车之前必须进入隧道的总人数,才能使司机克服恐惧(“若怪物出现在车队前方,会先吃掉他们”);
  • rr —— 在该卡车之后必须进入隧道的总人数,才能使司机克服恐惧(“若怪物出现在车队后方,会先吃掉他们”)。

由于道路狭窄,一旦怪物从任一侧出现,便无法逃脱德拉弗德。此外,车队顺序不可调整。虽然卡车的相对顺序不能改变,但可以将任意卡车从车队中移出,并将其无限期地留在隧道入口附近。作为车队负责人,你需要移除部分卡车,使得剩余卡车能安全驶入隧道,且剩余卡车的总价值 vv 尽可能大。

输入格式

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: v__i, c__i, l__i, r__i (1 ≤ v__i ≤ 104, 1 ≤ c__i ≤ 105, 0 ≤ l__i, r__i ≤ 105) — describe the i-th truck. The trucks are numbered from 1, counting from the front of the motorcade.

第一行输入包含一个整数 $ n (( 1 \leq n \leq 10^5 $)—— 表示车队中卡车的数量。接下来的 $ n $ 行,每行包含四个整数。第 $ i $ 行中的数字:$ v_i,, c_i,, l_i,, r_i (( 1 \leq v_i \leq 10^4 ,, 1 \leq c_i \leq 10^5 ,, 0 \leq l_i,, r_i \leq 10^5 $)—— 描述第 $ i $ 辆卡车。卡车编号从 1 开始,从前至后依次编号。

输出格式

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.

第一行输出数字 kk —— 进入隧道的卡车数量。
第二行输出 kk 个数字 —— 这些卡车的索引(按升序排列)。请注意,不允许改变卡车的顺序。若答案不唯一,输出任意一个即可。

输入输出样例

  • 输入#1

    5
    1 1 0 3
    1 1 1 2
    1 1 2 1
    1 1 3 0
    2 1 3 0

    输出#1

    4
    1 2 3 5
  • 输入#2

    5
    1 1 0 3
    10 1 2 1
    2 2 1 1
    10 1 1 2
    3 1 3 0

    输出#2

    3
    1 3 5

输入解题思路,AI测评打分。不知道怎么写?

首页