#T220. 宠物小精灵之收服

宠物小精灵之收服

Description

Pokémon is a story about Ash and his partner Pikachu going on adventures together.
One day, Ash and Pikachu arrive at a Pokémon Safari Zone, which contains many rare wild Pokémon. Ash wants to catch some of these wild Pokémon. However, wild Pokémon are not so easy to catch. For each wild Pokémon, Ash may need to use many Poké Balls to capture it, and during the capture process, the wild Pokémon will also deal some damage to Pikachu (thereby reducing Pikachu's HP).
When Pikachu's HP drops to 0 or below, Ash must end the hunt (because he needs to heal Pikachu), and the wild Pokémon that causes Pikachu's HP to drop to 0 or below will not be caught by Ash. When Ash runs out of Poké Balls, the hunt also ends.
We assume that when Ash encounters a wild Pokémon, he has two choices: catch it or leave it. If Ash chooses to catch it, he will definitely throw the required number of Poké Balls to capture the Pokémon, and Pikachu will definitely take the corresponding damage. If he chooses to leave it, Ash will not lose any Poké Balls, and Pikachu will not lose any HP.
Ash has two objectives: the primary goal is to catch as many wild Pokémon as possible. If the number of Pokémon that can be caught is the same, Ash hopes that Pikachu takes as little damage as possible (i.e., has as much remaining HP as possible), because they still have more adventures ahead.
Now, given the number of Poké Balls Ash has and Pikachu's initial HP, as well as the number of Poké Balls required to catch each wild Pokémon and the damage it will deal to Pikachu during the capture process, how should Ash choose which Pokémon to catch to achieve his goals?

Input Format

The first line of input contains three integers: N (0 < N ≤ 1000, the number of Poké Balls Ash has), M (0 < M ≤ 500, Pikachu's initial HP), and K (0 < K ≤ 100, the number of wild Pokémon).
The subsequent K lines each represent a wild Pokémon, containing two integers: the number of Poké Balls required to catch the Pokémon and the damage dealt to Pikachu during the capture process.

Output Format

The output consists of a single line containing two integers: C and R, representing the maximum number of Pokémon Ash can catch (C) and the maximum remaining HP Pikachu can have when catching C Pokémon (R).

10 100 5
7 10
2 40
2 50
1 20
4 20

3 30

10 100 5
8 110
12 10
20 10
5 200
1 110
0 100

Hint

For sample input 1: Ash chooses: (7,10) (2,40) (1,20). In this way, Ash captures a total of 3 Pokémon, and Pikachu receives 70 points of damage, leaving 100-70=30 points of health. Therefore, the output is 3 30.
For sample input 2: Ash cannot capture any Pokémon, and Pikachu will not receive any damage, so the output is 0 100.