#P16806. [蓝桥杯 2026 国 Python A] 糖分极限

    ID: 19147 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>动态规划 DP2026蓝桥杯国赛

[蓝桥杯 2026 国 Python A] 糖分极限

Problem Description

Programmer Xiao Lan needs to refactor a complex project tonight. Because the workload is very intense, he must consume sugar to replenish energy and keep his brain running at high speed.

However, according to the medical checkup report at the beginning of the year, Xiao Lan’s sugar tolerance limit is NN grams. Once the sugar in his body exceeds this limit, he will instantly fall asleep due to high blood sugar.

At the beginning, the sugar in Xiao Lan’s body is 00 grams.

The company has two kinds of desserts with unlimited supply:

  1. Donut: each time he eats one, the sugar in his body increases by aa grams.
  2. Iced cola: each time he drinks one can, the sugar in his body increases by bb grams.

To safely take in more energy, during the whole refactoring process, Xiao Lan may do jumping jacks to consume sugar (at most once). This immediately halves the current sugar in his body. If the value after halving is not an integer, discard the fractional part (i.e., take the floor; for example, 55 grams becomes 22 grams after halving).

During the entire sequence of operations, at any moment, the sugar in Xiao Lan’s body must not exceed the tolerance limit NN grams.

Now please help Xiao Lan compute: under the safety restriction above, what is the maximum number of grams of sugar he can reach in his body?

Input Format

One line contains three positive integers NN, aa, and bb separated by spaces, representing Xiao Lan’s sugar tolerance limit, the sugar increase from eating one donut, and the sugar increase from drinking one can of iced cola (unit: grams).

Output Format

Output one integer, representing the maximum sugar level (in grams) that Xiao Lan can reach within the safe range.

8 5 6
8

Hint

Sample Explanation

Xiao Lan can do the following operations:

  1. Eat one donut, and the sugar in his body becomes 55 grams.
  2. Do jumping jacks once, and the sugar in his body is instantly halved to 22 grams.
  3. Drink one can of iced cola, and the sugar in his body increases by 66 grams, reaching 88 grams.

At this point, it exactly reaches the tolerance limit 88 and cannot be increased further, so output 88.

Constraints

For 30%30\% of the testdata, 1N5001 \le N \le 500.

For all testdata, 1N1061 \le N \le 10^6, 1a,bN1 \le a, b \le N.

Translated by ChatGPT 5