I got a problem, and a solution to this problem. And I want to check if it's correct
Problem K. Camera Fine
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes
Balloon color: Orange
Suleiman has just obtained his driver's license and wants to show everyone how fast his car can go. He drives his car to Airport Road and starts speeding. On his way back, notifications begin appearing on his phone: one fine after another. Fortunately, Suleiman's car records its speed at various locations along the road, and he also remembers the location of every speed camera and the speed limit associated with each one.
According to the law, Suleiman is only fined if his speed exceeds the camera's speed limit by more than 9 km/h. If he is fined by a camera, the amount he must pay for that specific camera is equal to the difference between his speed and the camera's speed limit.
Your task is to determine the number of times Suleiman is fined and the total amount he must pay.
Input
- The first line contains two integers n and m (1 <= n, m <= 2 * 10^5): the number of recorded car logs and the number of cameras.
- Each of the following n lines contains two integers pi and si (1 <= pi, si <= 10^9): the car's position on the road and Suleiman's speed at that position.
- Each of the following m lines contains two integers ci and li (1 <= ci, li <= 10^9): the camera's location and its specific speed limit.
Note: It is guaranteed that all pi values are distinct, all ci values are distinct, and every camera location ci appears within the recorded car positions.
Output
Print two integers: the number of times Suleiman was fined and the total amount of the fines.
Examples
Example 1
Standard Input:
3 2
10 100
20 80
30 120
10 80
30 110
Standard Output:
2 30
Example 2
Standard Input:
4 4
1 30
2 40
3 50
4 60
1 10
2 20
3 30
4 40
Standard Output:
4 80
Example 3
Standard Input:
1 1
7 19
7 10
Standard Output:
0 0