Easy Problem
면접 대비시간 제한3초메모리 제한1024 MB
각 닭 i를 포함하는 급식기를 남기고, 어느 닭도 한계를 넘지 않도록 배분할 수 있는 최대 곡물 합을 i마다 구한다.
문제
Askhat is a prospective businessman. He quickly figured that programming is an unprofitable business, so he decided to open a chicken farm.
His farm consists of chickens ordered in a row. The -th chicken can eat at most grains. There are feeders, each described by integers , , . The -th feeder can feed the -th chicken if , and there are grains in this feeder.
Turns out that every business has its own pitfalls, in this case it has the face of chicken feeding control, represented by Ildar. He claims that every respectable chicken farm must have a chicken representative. That is, there must exist a chicken such that holds for every feeder . All feeders that don't obey this rule must be exterminated.
Now Askhat asks you to find, for each , what is the maximum number of grains that can be fed to chickens if we leave only feeders that can feed chicken .
입력
The first line contains a single integer () --- the number of test cases. Description of test cases follows.
The first line of each test case contains two integers , () --- the number of chickens and the number of feeders respectively.
The next line contains integers () --- the number of grains that chickens can eat.
Each of the next lines contains three integers , , (, ) --- description of the -th feeder.
It is guaranteed that both the sum of and the sum of for all test cases do not exceed .
출력
For each test case, print integers --- the answer to the problem.