eolymp
bolt
Try our new interface for solving problems

Bus

Vasilyich is a bus driver, and he has a really tough job, because he has to transfer passengers from point \textbf{A} to point \textbf{B} safely and as quickly as possible. Moreover, every driver must obey the road rules and regulations, otherwise, he will be fined by local police. Vasilyich’s route consists of \textbf{N} segments, \textbf{1} ≤ \textbf{N} ≤ \textbf{1000}, which he passes sequentially, starting from the beginning of first and finishing up at the end of \textbf{N}-th segment. Every segment has a length \textbf{D_i} kilometers, \textbf{1} ≤ \textbf{D_i} ≤ \textbf{1000}. Of course, there are speed limits on Vasilyich’s route. Every segment has its own speed limit \textbf{L_i}, \textbf{1} ≤ \textbf{L_i} ≤ \textbf{100000} km/h. In case the bus driver exceeds it, he is immediately stopped by a police officer, which requires spending \textbf{H_i} hours to fill all the relevant papers. \textbf{H_i} is known beforehand for each segment, \textbf{1} ≤ \textbf{H_i} ≤ \textbf{1000}. A driver can be stopped at most once in a segment. Bus is travelling along the route with a constant speed \textbf{S} that Vasilyich chooses at the beginning (point \textbf{A}). Time wasted for acceleration and deceleration of the vehicle is negligible, we assume it happens instantly. Maximum speed that the bus can achieve is \textbf{M}, \textbf{1} ≤ \textbf{M} ≤ \textbf{100000} km/h. Please help Vasilyich to choose the right speed in order to reach destination \textbf{B} as quickly as possible. Passengers like riding fast, so if there are multiple speeds possible choose the highest of them. \InputFile First line of the input contains an integer number \textbf{T} -- the number of testcases. Then \textbf{T} testcases follow, \textbf{T} ≤ \textbf{100}. Each test case starts with a line containing \textbf{2} numbers, separated by space: the number of segments \textbf{N} on Vasilyich’s route and maximum bus speed \textbf{M}. Each \textbf{i}-th line of the \textbf{N} following lines, contain space-separated variables \textbf{D_i}, \textbf{L_i} and \textbf{H_i}for \textbf{i}-th segment. \OutputFile For every testcase you should print speed \textbf{S} on a separate line.
Zaman məhdudiyyəti 2 saniyə
Yaddaşı istafadə məhdudiyyəti 256 MiB
Giriş verilənləri #1
1
1 100
1000 100 10
Çıxış verilənləri #1
100
Mənbə ACM ICPC 2012-2013, NEERC, Krasnojarsk