n chests numbered from 0 to n - 1. For chest i you know:
- unlocked[i] is 1 if it is not locked and 0 if it is;
- coins[i] is how many coins it holds;
- keys_inside[i] lists the chests whose keys lie inside it;
- chests_found[i] lists the chests you receive when you open chest i.
You start with the chests listed in start. A chest you own that is unlocked (or that you hold a key to) can be opened, and you take its coins, keys and new chests. Each chest is opened at most once, and receiving a chest you already have changes nothing. Return the total number of coins you can collect.unlocked=[1, 0, 0], coins=[3, 10, 4], keys_inside=[[2], [], [1]], chests_found=[[1, 2], [], []], start=[0] → 17
Chest 0 is open: it gives 3 coins, chests 1 and 2 and a key to 2. Chest 2 holds 4 coins and a key to 1, and chest 1 holds 10 coins. 17 in total.
unlocked=[0, 1], coins=[5, 6], keys_inside=[[], []], chests_found=[[], []], start=[0] → 0
Chest 0 is locked with no key, and the open chest 1 is not ours. Zero coins.
nunlocked[i] is 0 or 1keys_inside[i], chests_found[i] and start are between 0 and n - 1 and distinct within each listunlocked=[1, 0, 0], coins=[3, 10, 4], keys_inside=[[2], [], [1]], chests_found=[[1, 2], [], []], start=[0]
17
Run checks the first 3 tests in your browser. Submit checks all 83 tests on the server, hidden ones included.