CF1250C.Trip to Saint Petersburg

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are planning your trip to Saint Petersburg. After doing some calculations, you estimated that you will have to spend kk rubles each day you stay in Saint Petersburg — you have to rent a flat, to eat at some local cafe, et cetera. So, if the day of your arrival is LL, and the day of your departure is RR, you will have to spend k(R−L+1)k(R - L + 1) rubles in Saint Petersburg.

You don't want to spend a lot of money on your trip, so you decided to work in Saint Petersburg during your trip. There are nn available projects numbered from 11 to nn, the ii-th of them lasts from the day lil_i to the day rir_i inclusive. If you choose to participate in the ii-th project, then you have to stay and work in Saint Petersburg for the entire time this project lasts, but you get paid pip_i rubles for completing it.

Now you want to come up with an optimal trip plan: you have to choose the day of arrival LL, the day of departure RR and the set of projects SS to participate in so that all the following conditions are met:

  • your trip lasts at least one day (formally, R≥LR \ge L);
  • you stay in Saint Petersburg for the duration of every project you have chosen (formally, for each s∈Ss \in S L≤lsL \le l_s and R≥rsR \ge r_s);
  • your total profit is strictly positive and maximum possible (formally, you have to maximize the value of ∑s∈Sps−k(R−L+1)\sum \limits_{s \in S} p_s - k(R - L + 1), and this value should be positive).

You may assume that no matter how many projects you choose, you will still have time and ability to participate in all of them, even if they overlap.

你正在规划前往圣彼得堡的旅行。经过一些计算,你估计在圣彼得堡停留的每一天都需要花费 kk 卢布——例如租住公寓、在当地咖啡馆用餐等。因此,若你的抵达日期为 LL,离开日期为 RR,则你在圣彼得堡的总花费为 k(R−L+1)k(R - L + 1) 卢布。

你不想在旅行上花费过多金钱,因此决定在旅行期间于圣彼得堡工作。目前共有 nn 个可选项目,编号从 11 到 nn;其中第 ii 个项目的时间跨度为从第 lil_i 天到第 rir_i 天(含端点)。若你选择参与第 ii 个项目,则你必须在整个项目持续期间都留在圣彼得堡并工作,但完成该项目后你将获得 pip_i 卢布的报酬。

现在,你需要制定一个最优旅行计划:选择抵达日期 LL、离开日期 RR,以及参与的项目集合 SS,使得满足以下所有条件:

  • 旅行至少持续一天(形式化地,R≥LR \ge L);
  • 对于你所选的每个项目 s∈Ss \in S,你均需在圣彼得堡停留至其整个持续期间(形式化地,对每个 s∈Ss \in S,均有 L≤lsL \le l_s 且 R≥rsR \ge r_s);
  • 你的总利润严格为正,且尽可能大(形式化地,需最大化 ∑s∈Sps−k(R−L+1)\sum \limits_{s \in S} p_s - k(R - L + 1) 的值,且该值必须大于 00)。

你可以假设:无论你选择多少个项目,你总有足够的时间和能力参与所有选定的项目,即使它们的时间段存在重叠。

输入格式

The first line contains two integers nn and kk (1≤n≤2⋅1051 \le n \le 2\cdot10^5, 1≤k≤10121 \le k \le 10^{12}) — the number of projects and the amount of money you have to spend during each day in Saint Petersburg, respectively.

Then nn lines follow, each containing three integers lil_i, rir_i, pip_i (1≤li≤ri≤2⋅1051 \le l_i \le r_i \le 2\cdot10^5, 1≤pi≤10121 \le p_i \le 10^{12}) — the starting day of the ii-th project, the ending day of the ii-th project, and the amount of money you get paid if you choose to participate in it, respectively.

第一行包含两个整数 nn 和 kk(1≤n≤2⋅1051 \le n \le 2\cdot10^5,1≤k≤10121 \le k \le 10^{12}),分别表示项目的数量以及你在圣彼得堡每天需要花费的金额。

接下来是 nn 行,每行包含三个整数 lil_i、rir_i、pip_i(1≤li≤ri≤2⋅1051 \le l_i \le r_i \le 2\cdot10^5,1≤pi≤10121 \le p_i \le 10^{12}),分别表示第 ii 个项目的起始日期、结束日期,以及若你选择参与该项目所能获得的报酬金额。

输出格式

If it is impossible to plan a trip with strictly positive profit, print the only integer 00.

Otherwise, print two lines. The first line should contain four integers pp, LL, RR and mm — the maximum profit you can get, the starting day of your trip, the ending day of your trip and the number of projects you choose to complete, respectively. The second line should contain mm distinct integers s1s_1, s2s_2, ..., sms_{m} — the projects you choose to complete, listed in arbitrary order. If there are multiple answers with maximum profit, print any of them.

如果无法规划一次严格正收益的旅行,则仅输出整数 00。

否则,输出两行。第一行应包含四个整数 pp、LL、RR 和 mm —— 分别表示你能获得的最大收益、旅行的起始天数、旅行的结束天数以及你选择完成的项目数量。第二行应包含 mm 个互不相同的整数 s1s_1、s2s_2、...、sms_{m} —— 表示你选择完成的项目,顺序任意。若存在多个具有最大收益的方案,输出其中任意一个即可。

输入输出样例

  • 输入#1

    4 5
    1 1 3
    3 3 11
    5 5 17
    7 7 4

    输出#1

    13 3 5 2
    3 2
  • 输入#2

    1 3
    1 2 5

    输出#2

    0
  • 输入#3

    4 8
    1 5 16
    2 4 9
    3 3 24
    1 5 13

    输出#3

    22 1 5 4
    3 2 1 4

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

首页