Baskets of Gold Coins
InterviewTime limit1sMemory limit128 MB
Given the total weight of coins drawn with counts 1..N-1 from N baskets, find which basket holds the lighter coins.
- Level
Medium4 of 10
- Topics
- Math, Brute force, Implementation, Prefix sum
- Solved
- No attempts yet
Problem
You are given baskets of gold coins, numbered from to . In every basket except one, each gold coin weighs grams. In the single exceptional basket, each gold coin weighs grams and is therefore lighter than the others.
A wizard takes coin from Basket , coins from Basket , and so on, up to coins from Basket . He takes no coins from Basket . He then weighs all of the selected coins together and, from that single weighing, determines which of the baskets holds the lighter coins.
Emulate the wizard's computation.
Input
The input consists of one or more lines; each line describes one instance of the problem. Each line contains four positive integers separated by single spaces. The first three are , , and as described above, and the fourth is the weight obtained by weighing the selected coins.
is at least and at most , is at most , and is smaller than .
Output
For each instance, print a single line containing one integer: the number of the basket that holds the lighter coins.