中級 0件解決済み 正答率0%

Smallest Missing Coin Sum

Find the first positive amount that cannot be made from the available coins.

You may select any subset of the supplied coins. Each individual coin may be used at most once, even when multiple coins share a value. Find the smallest positive integer amount that no selection can produce.

Implement missing_coin_sum(coins).

Input

coins: The values of the available coins; duplicates represent separate coins.

Output

Return the smallest positive impossible amount.

制約

1 ≤ number of coins ≤ 200,000. Each value is between 1 and 1,000,000,000.

例

例 1
入力:
coins = [1, 1, 4]

期待される出力:
expected = 3
入力:
std::vector<long long> coins = {1, 1, 4};

期待される出力:
long long expected = 3;
入力:
long[] coins = new long[] {1, 1, 4};

期待される出力:
long expected = 3;

解説

Amounts 1 and 2 use the one-valued coins. No available subset totals 3.

例 2
入力:
coins = [2, 3]

期待される出力:
expected = 1
入力:
std::vector<long long> coins = {2, 3};

期待される出力:
long long expected = 1;
入力:
long[] coins = new long[] {2, 3};

期待される出力:
long expected = 1;

解説

There is no way to make 1 because every coin is worth at least 2.

参考資料

この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。