Horns and Hooves
InterviewTime limit2sMemory limit1024 MB
Given horn types and hoof types, each with a cost and a count, count the pairs where the horn costs more, costs the same, or costs less than the hoof.
- Level
Medium4 of 10
- Topics
- Sorting, Prefix sum
- Solved
- No attempts yet
Problem
The attempted assault on Koreyko, a secret millionaire, was a disastrous failure. The foster brothers Panikovskiy and Balaganov have barricaded themselves in their office. They are playing a strange game. One of them has a room full of horns, and the other has a room full of hooves. They are taking all possible pairs (horn, hoof), and whoever has the more expensive object in the pair wins. They want to know one thing: who will win more often. Their psychological integrity has been somewhat compromised, and it might be beyond their powers at the moment to solve this problem by their own efforts. Please help them, and they will thank you... with horns and hooves.
Input
The first line of the input contains two integers and , where is the number of horn types and is the number of hoof types ().
The following lines describe the horn types, one type per line. Each type is defined by two positive integers. The first integer is the cost of one horn of that type, and the second integer is the supply of horns of that type (the number of individual units).
The following lines describe the hoof types in the same format.
The cost of any horn or hoof does not exceed . The number of horns or hooves of each type does not exceed .
Output
The output must contain three numbers: the number of pairs where the price of the horn is greater than the price of the hoof, the number of pairs where the prices are equal, and the number of pairs where the price of the horn is less than the price of the hoof, in that order.