| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 2048 MB | 65 | 21 | 20 | 32.258% |
Amaru is buying souvenirs in a foreign shop. There are $N$ types of souvenirs. There are infinitely many souvenirs of each type available in the shop.
Each type of souvenir has a fixed price. Namely, a souvenir of type $i$ (0ドル \leq i < N$) has a price of $P[i]$ coins, where $P[i]$ is a positive integer.
Amaru knows that souvenir types are sorted in decreasing order by price, and that the souvenir prices are distinct. Specifically, $P[0] > P[1] > \cdots > P[N-1] > 0$. Moreover, he was able to learn the value of $P[0]$. Unfortunately, Amaru does not have any other information about the prices of the souvenirs.
To buy some souvenirs, Amaru will perform a number of transactions with the seller.
Each transaction consists of the following steps:
Note that there are no coins or souvenirs on the table before a transaction begins.
Your task is to instruct Amaru to perform some number of transactions, so that:
Amaru does not have to minimize the number of transactions and has an unlimited supply of coins.
You should implement the following procedure.
void buy_souvenirs(int N, long long P0)
The above procedure can make calls to the following procedure to instruct Amaru to perform a transaction:
std::pair<std::vector<int>, long long> transaction(long long M)
Output isn't correct: Invalid argument. Note that contrary to $P[0],ドル the value of $P[N-1]$ is not provided in the input.The behavior of the grader is not adaptive. This means that the sequence of prices $P$ is fixed before buy_souvenirs is called.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 4 | $N = 2$ |
| 2 | 3 | $P[i] = N - i$ for each $i$ such that 0ドル \leq i < N$. |
| 3 | 14 | $P[i] \leq P[i+1] + 2$ for each $i$ such that 0ドル \leq i < N - 1$. |
| 4 | 18 | $N = 3$ |
| 5 | 28 | $P[i+1] + P[i+2] \leq P[i]$ for each $i$ such that 0ドル \leq i < N-2$. <br> $P[i] \leq 2 \cdot P[i+1]$ for each $i$ such that 0ドル \leq i < N-1$. |
| 6 | 33 | No additional constraints. |
Consider the following call.
buy_souvenirs(3, 4)
There are $N = 3$ types of souvenirs and $P[0] = 4$. Observe that there are only three possible sequences of prices $P$: $[4, 3, 2],ドル $[4, 3, 1],ドル and $[4, 2, 1]$.
Assume that buy_souvenirs calls transaction(2). Suppose the call returns $([2], 1),ドル meaning that Amaru bought one souvenir of type 2ドル$ and the seller gave him back 1ドル$ coin. Observe that this allows us to deduce that $P = [4, 3, 1],ドル since:
transaction(2) would have returned $([2], 0)$.transaction(2) would have returned $([1], 0)$.Then buy_souvenirs can call transaction(3), which returns $([1], 0),ドル meaning that Amaru bought one souvenir of type 1ドル$ and the seller gave him back 0ドル$ coins. So far, in total, he has bought one souvenir of type 1ドル$ and one souvenir of type 2ドル$.
Finally, buy_souvenirs can call transaction(1), which returns $([2], 0),ドル meaning that Amaru bought one souvenir of type 2ドル$. Note that we could have also used transaction(2) here. At this point, in total Amaru has one souvenir of type 1ドル$ and two souvenirs of type 2ドル,ドル as required.
Input format:
N
P[0] P[1] ... P[N-1]
Output format:
Q[0] Q[1] ... Q[N-1]
Here $Q[i]$ is the number of souvenirs of type $i$ bought in total for each $i$ such that 0ドル \leq i < N$.
C++17, C++20, C++23, C++26, C++17 (Clang), C++20 (Clang)