King of Hot Pot
시간 제한4초메모리 제한512 MB
각 k=1부터 n까지, a_i부터 먹을 수 있고 먹는 데 b_i가 걸리는 요리 중 k개를 하나씩 먹어 끝내는 최소 시각을 구한다.
문제
Little Q is enjoying hot pot together with Tangjz. There are dishes of meat in the boiling water, labeled by . The -th dish of meat will be ready at moment , and it will take Little Q units of time to fully eat it. Little Q can start eating dish at any moment , and then he has to eat it until moment . Little Q can't be eating more than one dish of meat at the same time.
Little Q is called "King of Hot Pot", and he wants to show off before Tangjz by fully eating dishes of meat as soon as possible. The timer starts at moment . Please write a program to help Little Q, for each independently (), find dishes of meat and the order to eat them such that the total time before he fully eats dishes is minimized. Note that any waiting time is also included in the answer.
입력
The first line contains a single integer (), the number of test cases. For each test case:
The first line contains an integer () denoting the number of dishes of meat.
Each of the following lines contains two integers and () describing a dish of meat.
It is guaranteed that the sum of all is at most .
출력
For each test case, output a single line containing integers, the -th () of which is the minimum total time before Little Q can fully eat dishes of meat.