ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

2207. Catansonnes

Time limit: 2.0 second
Memory limit: 256 MB
Vanim has invented a cool board game — Catansonnes. The game takes place on a grid of size W × H. Each cell can contain either a house, a farm, or nothing.
The goal of the game is to grow as many pumpkincores as possible. To do this, residents need to be sent to work on farms. There are a total of n houses and m farms on the field. Each house has coordinates (hxi, hyi), and initially, there are ai people living in it. Each farm has coordinates (fxi, fyi), and it has bi job positions.
To move between houses and farms, residents need horses. Let’s assume that each resident has a horse, and all horses have the same horsepower D. Vanim has not yet determined the exact value of horsepower; this number will be defined later during the game balancing. A resident can move from a house to a farm or from a farm to a house if the Manhattan distance between them does not exceed D. That is, movement between the i-th house and the j-th farm is allowed in both directions if |hxifxj| + |hyifyj| ≤ D. Movement from house to house, as well as from farm to farm, is prohibited by the rules of the game. The capacity of houses and farms is unlimited: at any moment, any number of people can be in each house and each farm.
At the end of the game, the number of pumpkincores is counted. Each farm grows as many pumpkincores as there are job positions occupied on it. In other words, one pumpkincore grows on the farm for each person present there, but no more than the number of job positions available on that farm. Houses do not contribute to the score.
Of course, Vanim wants to collect the maximum score. However, he is not looking for an easy way, so he wants to achieve this with the least possible horsepower. Help him by determining the maximum number of pumpkincores achievable in the game and the minimum horsepower that will allow reaching this number.

Input

The first line contains two integers W and H — the width and height of the field in cells (1 ≤ W, H ≤ 109).
The second line contains two integers n and m — the number of houses and farms, respectively (1 ≤ n, m ≤ 104).
In the next n lines, three integers hxi, hyi and ai are given, separated by spaces — coordinates of the next house and the initial number of people in it (1 ≤ hxiW, 1 ≤ hyiH, 1 ≤ ai ≤ 109).
In the following m lines, three integers fxi, fyi and bi are given, separated by spaces — coordinates of the next farm and the number of job positions available on it (1 ≤ fxiW, 1 ≤ fyiH, 1 ≤ bi ≤ 109).
It is guaranteed that no two buildings are located in the same cell at the same time.

Output

In a single line, output two integers separated by a space — the maximum possible score in the game and the minimum possible horsepower required to achieve the maximum score.

Sample

inputoutput
11 11
4 4
1 1 2
7 1 1
1 11 2
11 11 1
4 4 1
10 4 2
4 11 1
8 11 2
6 7
Problem Author: Ivan Kogut
Problem Source: University academic school olympiad in informatics 2022