Conquest

0.52

It is summer in the land of Max-Flow and Lord Push-Relabel wants to
build a swimming pool in the yard next to his castle, which will cost
g gold coins. So he is sending his invincible army to conquer some of
the n nearby towns. His soldiers can conquer one town per day, and
afterwards they will use one of the following methods to acquire gold
from it:

0.48

[image]

- Taxes: the town will pay t_(i) gold coins every day, starting the same
  day it is conquered.

- Sacking: the army will get s_(i) gold coins by looting the town the
  very same day it is conquered, but this will leave the town unable to
  pay taxes in the future.

Lord Push-Relabel wants to minimize the number of days to acquire the
desired amount of gold g. Please plan which towns to conquer, in what
order, and for each conquered town whether it should be taxed or sacked.

Input

Input consists of several cases. Every case begins with g and n,
followed n pairs t_(i) s_(i). Assume 1 ≤ g ≤ 10¹⁷, 1 ≤ n ≤ 1000,
1 ≤ t_(i) ≤ 10⁷, and t_(i) < s_(i) ≤ 10¹⁴.

Output

For every case, print the minimum number of days needed to collect at
least g gold coins.

Problem information

Author: Félix Miravé

Generation: 2026-01-25T11:24:42.996Z

© Jutge.org, 2006–2026.
https://jutge.org
