#P15296. [ROI 2012 Day 1] apricot 杏干

    ID: 17375 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 显示难度暂无评定 上传者: 标签>动态规划 DP2012二分ROI(俄罗斯)

[ROI 2012 Day 1] apricot 杏干

Background

Translation source: loj #5457. 「ROI 2012 Day 1」杏干。

Problem Description

In ancient times, the Golden Horde collected gold coins as tribute every year. The famous Crimean Khan Giray decided to play a trick: when paying tribute of NN gold coins, he mixed in one lighter counterfeit coin. This was reported to the Golden Horde’s treasurer. To find the counterfeit coin, the treasurer decided to use a magical balance powered by dried apricots.

On each side of the magical balance, a pile of gold coins is placed. The balance can tell whether the two piles have the same weight. If the weights are different, it will indicate which pile is lighter. If the weights are the same, the balance consumes RR dried apricots; if the weights are different, it consumes UU dried apricots.

As a lover of dried apricots, the treasurer wants to find the counterfeit coin while saving as many dried apricots as possible.

You need to write a program that, given the number of coins NN (with exactly one lighter counterfeit coin), computes the minimum number of dried apricots needed to guarantee finding the counterfeit coin.

Input Format

The input file contains only one line with three integers N,R,UN, R, U (2≤N≤1000000,1≤R,U≤1000000)(2 \leq N \leq 1000000, 1 \leq R, U \leq 1000000), representing the number of coins, the number of dried apricots consumed when the weights are equal, and the number of dried apricots consumed when the weights are different. The three numbers are separated by spaces.

Output Format

The output file should contain one integer, indicating the minimum number of dried apricots needed to guarantee finding the counterfeit coin.

4 3 1
2
3 3 1

3

15 2 3

8
10 2 1

3

Hint

The detailed additional constraints and scores for each subtask are shown in the table below.

Subtask Score Additional Constraints
11 4040 N,U,R≤200N, U, R \leq 200
22 3030 N,U,R≤2000N, U, R \leq 2000
33 N,U,R≤1000000N, U, R \leq 1000000

Translated by ChatGPT 5