I am new to competitive programming and I was trying out this problem.
Problem https://cses.fi/problemset/task/2183.
Looked up many places on the internet but still I am unable to understand it.
Can anyone help me with same. Regards
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
I am new to competitive programming and I was trying out this problem.
Problem https://cses.fi/problemset/task/2183.
Looked up many places on the internet but still I am unable to understand it.
Can anyone help me with same. Regards
Название |
---|
Start by observing what is important — the number of coins of each denomination. Now it's easy to note that if you don't have a coin of denomination $$$1$$$ then $$$1$$$ is your answer right away.
For other cases you can do the following — Build a map, $$$fre$$$ that stores frequency of each denomination. Iterate over all the values, keep a track of prefix sums i.e. $$$pref[i]$$$ denotes $$$\sum j*fre[j]$$$ for $$$j \le i$$$. Suppose the current coin value is $$$i$$$, then the claim is if you can create all the sums $$$<i$$$, then you can create all the sums up to $$$pref[i]$$$. Now just check that the next denomination you encounter does not exceed this value by more than $$$1$$$.
The claim can be simply proven by induction.