spoj#GNTFNTN. Giant fountain
Giant fountain
The Dystopian government has installed a giant fountain in front of the parliament building. The fountain consists of N levels stacked one on top of the other and is situated on top of a large tank of infinite capacity. The levels of the fountain are numbered 1 to N from top to bottom. The top l1 levels are identical with capacity c1, the next l2 levels identical with capacity c2,... the final lK levels with capacity cK. Here l1 + l2 + ... lK = N.
When water is added to level i beyond its capacity, the excess water overflows to level i+1. Water overflowing from level N is collected in the tank. Water is added to the levels in the following fashion. First, w1 amount of water is added to each level i such that s1 ≤ i ≤ e1. Then w2 amount of water is added to each s2 ≤ i ≤ e2... Finally wM amount is added to sM ≤ i ≤ eM. Note that water might be added to the same level multiple times in this fashion. You have to find out the amount of water that has overflowed to the tank at the bottom, and the total number of levels of the fountain that are completely filled
Input
The first line of the input contains T (≤10), the number of test cases. Following this are the descriptions of the test cases.
The first line of the description of a test case contains space separated integers N (≤2x108), K (≤2000) and M (≤104). Following this are K lines, each containing a space separated pair of integers. These are the (li,ci) pair as explained in the problem statement. Here l1 + l2 + ... lK = N and ci ≤ 108. This is followed by M lines, each containing a space separated triplet of integers. These are (si,ei,wi) as explained in the problem statement. 1 ≤ si ≤ ei ≤ N and wi ≤ 106
Output
For each test case output a space separated pair of integers : The total amount of water that has overflowed to the tank and the number of levels of the fountain that are completely filled.
Example
Input: 1 10 2 1 5 6 5 3 3 9 5</p>Output: 5 5