infO(1)Cup 2025 Day 1 - Mirror | SkiCircuit

This was the problem page during the contest. Access the current page here.
Time limit: 0.4s Memory limit: 256MB Input: Output:

After leaving Los Angeles, Little AD arrived in the InfO(1)Cup Ski Resort, the largest ski resort in the InfO(1)Cup Kingdom. The ski resort is made of N+1N+1 points numbered from 00 to NN. The height of point ii is HiH_i, and H0=0H_0 = 0. There are no two points that have the same height.

For any two points ii and jj with Hi<HjH_i \lt H_j, there exists one chairlift that takes skiers from point ii to point jj and one slope that takes skiers from point jj to point ii. Taking the slope from point jj to point ii takes exactly HjHiH_j - H_i seconds. Please note that when taking the slope from point jj to point ii, skiers are not required to visit all points pp with Hi<Hp<HjH_i \lt H_p \lt H_j. Moreover, when taking a chairlift from point ii to point jj, skiers cannot stop at any point pjp \neq j.

It takes a skier UiU_i seconds to get on a chairlift at point ii (regardless of where the chairlift goes) and CiC_i seconds to get off a chairlift at point ii (regardless of where that chairlift comes from). U0=C0=0U_0 = C_0 = 0.

Little AD wants to make a KK-second circuit. That is, he wants to start from point 00, visit all other NN points exactly once, and then return to point 00, and he wants to spent at least KK seconds on the slopes.

Little AD hates (as much as any proven skier) to stay in one point for too long. Therefore, let WiW_i be the total time Little AD spends at point ii, and let MM be the maximum value along all WiW_i. Note that W0=0W_0 = 0 and, for all 1iN1 \leq i \leq N:

  • Wi=0W_i = 0, if Little AD reaches point ii on a slope and leaves point ii on a slope;
  • Wi=CiW_i = C_i, if Little AD reaches point ii with a chairlift and leaves point ii on a slope;
  • Wi=UiW_i = U_i, if Little AD reaches point ii on a slope and leaves point ii with a chairlift;
  • Wi=Ui+CiW_i = U_i + C_i, if Little AD reaches point ii with a chairlift and leaves point ii with a chairlift.

Task

Now Little AD wonders: how much time does he need to spend in a single point so that he skis for a total of at least KK seconds? That is, what is the minimum value of MM he could achieve in order to spend at least KK seconds on the slopes?

Little AD needs your help! For TT given scenarios, you must find the minimum value of MM and help Little AD enjoy his well deserved ski holiday!

Input data

The first line of input contains TT, the number of scenarios your program will have to solve. For each of the TT scenarios, the first line will contain NN and KK. The ii-th following NN lines will contain three values HiH_i, UiU_i, CiC_i. Please note that the input does not contain the values H0H_0, U0U_0 and C0C_0, since H0=U0=C0=0H_0 = U_0 = C_0 = 0.

Output data

There should be exactly TT lines of output, with the ii-th line of output containing the answer for the ii-th scenario.

Constraints and clarifications

  • It is guaranteed that Little AD can ski at least KK seconds;
  • 1T2001 \leq T \leq 200;
  • Let N\sum N denote the sum of the values of NN for all scenarios.
  • 1N200 0001 \leq \sum N \leq 200 \ 000;
  • 1K10121 \leq K \leq 10^{12};
  • 1Hi,Ui,Ci1061 \leq H_i, U_i, C_i \leq 10^6, for all 1iN1 \leq i \leq N.
# Points Restrictions
1 6 1N101 \leq \sum N \leq 10
2 9 1N171 \leq \sum N \leq 17
3 19 1N3001 \leq \sum N \leq 300
4 22 1N2 0001 \leq \sum N \leq 2 \ 000
5 44 No further restrictions.

Example

stdin

2
3 5
1 8 6
5 3 2
2 6 8
3 6
1 8 6
5 3 2
2 6 8

stdout

2
8

Explanation

First scenario. Little AD gets on the chairlift at point 00, then he gets off at point 22 and skies down to point 33. There he skies down to point 11, where he skies back to point 00.

W0=W1=W3=0; W2=2W_0 = W_1 = W_3 = 0;\ W_2 = 2

Second scenario. Little AD gets on the chairlift at point 00 and goes up to point 22, where he gets off. Then he skies down to point 11. There he gets on the chairlift and goes up to point 33, where he gets down and skies back to point 00.

W0=0; W1=W3=8; W2=2W_0 = 0;\ W_1 = W_3 = 8;\ W_2 = 2

Log in or sign up to be able to send submissions!