CarrotBoxesEasy
SRM 495 · 2010-11-01 · by rng_58
SRM 495 · 2010-11-01 · by rng_58 · Simulation
Problem Statement
Problem Statement
Rabbit Hanako has N boxes of carrots numbered 0 through N-1. The i-th box contains carrots[i] carrots.
She decides to eat K carrots from these boxes. She will eat the carrots one at a time, each time choosing a carrot from the box with the greatest number of carrots. If there are multiple such boxes, she will choose the lowest numbered box among them.
Return the number of the box from which she will eat her last carrot.
She decides to eat K carrots from these boxes. She will eat the carrots one at a time, each time choosing a carrot from the box with the greatest number of carrots. If there are multiple such boxes, she will choose the lowest numbered box among them.
Return the number of the box from which she will eat her last carrot.
Constraints
- carrots will contain between 1 and 50 elements, inclusive.
- Each element of carrots will be between 1 and 100, inclusive.
- K will be between 1 and the sum of all elements of carrots, inclusive.
Examples
0)
{5, 8}
3
Returns: 1
She will choose three carrots from box 1.
1)
{5, 8}
4
Returns: 0
After she chooses three carrots from box 1, both boxes contain 5 carrots. She will choose the 4th carrot from the lowest indexed box.
2)
{4, 9, 5}
18
Returns: 2
3)
{13, 75, 24, 55}
140
Returns: 0
4)
{14, 36, 52, 86, 27, 97, 3, 67}
300
Returns: 4
Submissions are judged against all 52 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class CarrotBoxesEasy with a public method int theIndex(vector<int> carrots, int K) · 52 test cases · 2 s / 256 MB per case