402345: GYM100733 J Summer Wars

Memory Limit:64 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Summer Warstime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output

The mafia is finally resting after a year of hard work and not so much money. Mafianca, the little mascot of the gang wanted to go to the beach.

Little did they know that the rival gang had prepared a trap to the little girl and her rubber duck. They know that Mafianca, despite loving the beach, hates water. So they set up some water sprayers to ruin her day. The beach can be seen as a plane. The sprayers are located at different (x, y) points along the shore. Each sprayer is so strong that it creates an infinite line of water, reaching every point with x-coordinate equal to the sprayer.

Mafianca's bodyguards figured this plan out. They didn't have the time to destroy the sprayers, so they decided to do something else. Lying around on the beach was a piece of modern art: a bunch of walls, represented by horizontal line segments, painted by some futuristic anonymous artist. Those walls can be moved, but they can only be moved together and horizontally.

The bodyguards decided that they would try to move this piece of art in order to block the most sprayers they can. A sprayer is blocked if there's at least one wall in both of its sides.

How many sprayers can they block?

Input

Input begins with the number of sprayers, n (1 ≤ n ≤ 1000) and the number of walls in the modern art, m (1 ≤ m ≤ 1000).

Follows n lines, each with two intergers, y and x (0 ≤ y, x ≤ 106), indicating that there's a sprayer at position x, y.

Then follows m lines, each with three integers: y, xbegin and xend (0 ≤ y ≤ 106) and (0 ≤ xbegin < xend ≤ 106) denoting a wall in the modern art has y-coordinate y, begins at xbegin and ends at xend. No wall will have a y-coordinate shared with a sprayer and the walls with same y will not intersect.

Output

Print the number of sprayers that can be blocked.

ExamplesInput
1 1
2 2
3 1 3
Output
0
Input
2 5
2 3
2 6
1 0 2
4 0 4
0 2 3
1 4 5
3 5 7
Output
2
Input
4 5
2 3
2 8
2 20
5 1
1 0 2
4 0 4
0 2 3
1 4 5
3 5 7
Output
2
Input
3 4
2 0
2 4
4 7
1 0 2
3 1 3
5 0 2
5 3 4
Output
2
Note

In the test case #4, the beach looks like this:

A solution would be

Source/Category

加入题单

算法标签: