Opening your workspace…
Workspace/Coding room
Opening your workspace…
You finally found a Minecraft librarian selling Mending. He sells you one book, folds his arms, and refuses to sell you another. You still have three sets of boots to fix. Fortunately there are other librarians in the village.
Each librarian lists a price in emeralds per Mending book and the number of copies available before the next restock. You have plenty of ordinary books to trade in. Given those offers and the number of Mending books you need today, return the fewest emeralds you can spend. Return -1 if the whole village is short.
[[6,2],[4,2]], 3Output14Buy both four-emerald books and one six-emerald book.
[[4,1]], 2Output-1The librarian has only one book.
Use the lowest-priced copies before buying a more expensive book.
function solve(offers, needed) { // Write your solution here. }
Tab inserts two spaces. Shift+Tab outdents. Use the arrow keys and Tab to choose a suggestion. Press Escape, then Tab, to leave the editor. Press Control or Command with apostrophe to run samples or with Enter to submit.