루미 알고리즘

#1570골드Cutting Wood

PO 2023 온라인 예선코딩출제 Johan Sannemo영어 원문이 문제가 어렵다면 — 배우는 순서 보기

영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)

Problem

The year 2022 has been marked by a series of sensational news topics, one of which is the very high electricity prices in southern Sweden. For Leah, who lives in a villa in Skåne, this unfortunately means that her bitcoin mining is currently not quite paying off due to electricity costs. However, something trivial as this will not stop her. Energy is ultimately just energy, and electricity can just as well be obtained by burning wood!

Leah has a forest with N trees that she plans to cut down to make firewood. The i-th of these trees grows at a rate of v_i nanometers per second and currently has a length of l_i nanometers. After t_i seconds, the tree also becomes too old and stops growing.

Leah needs firewood from trees whose total length is S nanometers to be able to power her bitcoin mining for a year, but she is unsure if the trees can grow to that length quickly enough. Can you calculate how many seconds it will take before the lengths of Leah's trees have at least a total of S nanometers?

Input

The first line of input contains the integers N (1 ≤ N ≤ 200,000), the number of trees in Leah's forest, and S (1 ≤ S ≤ 10^9), the total length of trees Leah needs.

The following N lines describe her trees. The i-th line contains the three integers l_i (0 ≤ l_i ≤ 10^9), v_i (0 ≤ v_i ≤ 10^9), and t_i (0 ≤ t_i ≤ 10^9), as described earlier.

It is guaranteed that the forest will have sufficient length for Leah at some point.

Output

Print the smallest integer k, such that after k whole seconds, Leah's forest has sufficient total length.

Scoring

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.

GroupPointsConstraints
116N = 1
217N ≤ 1000, S ≤ 1000
317N ≤ 1000
450No additional constraints.

예제

예제 1

입력
1 5
2 1 3
출력
3

예제 2

입력
3 30
4 4 2
1 1 10
2 3 5
출력
4

예제 3

입력
1 10
11 1 1
출력
0

출처 표기

출처: Programmeringsolympiaden 2023년 온라인 예선 · 원문 페이지 · 이용 조건 CC BY-SA · LaTeX 원문을 화면용 글로 옮겼습니다(수식·표의 모양이 다를 수 있습니다). 내용은 고치지 않았습니다.

크리에이티브 커먼즈 저작자표시-동일조건변경허락.

문제 출처: 한국정보올림피아드(KOI) (CC BY-NC-SA 4.0) · International Olympiad in Informatics (IOI) (CC BY) · Centre for Education in Mathematics and Computing (CEMC), University of Waterloo (CC BY-NC 4.0) · Programmeringsolympiaden (CC BY-SA) · CSES Problem Set (Antti Laaksonen) (CC BY-NC-SA 4.0). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.