시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 1024 MB | 1 | 1 | 1 | 100.000% |
Alice and Bob are playing a cooperative game. They hold $b^p$ dollars between them, for given integers $b$ and $p$. Alice initially holds $x$ dollars, and Bob holds $b^p - x$ dollars. Alice and Bob want to consolidate their money, so one person holds all the money.
In each transaction, one player can choose to send the other player $b^y$ dollars, for some integer $y$ with $0 \le y < p$. But each player wants to initiate as few transactions as possible. They are willing to cooperate such that the player that initiates the most transactions (the busiest player), initiates as few as possible.
Alice and Bob want to know the fewest number of transactions that the busiest player needs to initiate to complete the transfer.
The first line of input contains two integers $b$ ($2 \le b \le 100$) and $p$ ($2\le p\le 1000$), where $b$ is the base, and $p$ is the number of digits.
The next line contains $p$ integers $x_{p-1}, x_{p-2}, \ldots, x_0$, separated by spaces, with $0\le x_i<b$ and $0<x_{p-1}$. These are the base-$b$ digits of the value of $x$, with the most significant digit first. Specifically, $x=\sum_{0\le i<p} b^i x_i$. Note that they are given in order from the highest power to the lowest. For example, in the sample, 4 2 7 8 6
with $b=10$ represents the base $10$ number $42\,786$.
Output a single integer, which is the minimum number of transactions the busiest player must initiate to transfer all the money to either Alice or Bob.
10 5 4 2 7 8 6
7
ICPC > Regionals > North America > Mid-Atlantic Regional > 2022 Mid-Atlantic USA Regional Contest > Division 1 E번
ICPC > Regionals > North America > South Central USA Regional > 2022 South Central USA Regional Contest > Division 1 E번
ICPC > Regionals > North America > Southeast USA Regional > 2022 Southeast USA Regional Programming Contest > Division 1 E번
ICPC > Regionals > North America > North Central North America Regional > 2022 North Central NA Regional Contest B번
ICPC > Regionals > North America > Pacific Northwest Regional > 2022 ICPC Pacific Northwest Region > Division 1 L번