FryingHamburgers
SRM 159 · 2003-08-12 · by dimkadimon
Problem Statement
In order to cook hamburgers, a chef must fry them 5 minutes on each side. However, the two 5 minute intervals do not have to happen consecutively.
panSize indicates how many hamburgers can fit into the given pan, while hamburgers represents the number of hamburgers that need to be fried. Given panSize and hamburgers return the minimum amount of time (in minutes) required to fry all the hamburgers.
Constraints
- panSize is between 1 and 1000 inclusive.
- hamburgers is between 0 and 1000 inclusive.
2 3 Returns: 15
We will assume that the three hamburgers given are A, B and C. The chef could fry A and B on one side, taking up 5 minutes. Then remove B and fry A on its second side together with C on its first side. After 5 minutes, remove A and fry B and C on their second sides for another 5 minutes. The total time used is 15 minutes.
3 4 Returns: 15
We will assume that the four hamburgers given are A, B, C and D. The chef could fry A, B and C on one side, taking up 5 minutes. Then remove C and fry A and B on their second side together with D on its first side. So after a total of 10 minutes A and B are completely fried, while C and D are fried on one side only. Finally, the chef fries C and D on their second side, taking another 5 minutes. The total time used is 15 minutes.
3 2 Returns: 10
100 0 Returns: 0
There are no hamburgers, so we do not have to fry anything.
3 8 Returns: 30
Submissions are judged against all 56 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class FryingHamburgers with a public method int howLong(int panSize, int hamburgers) · 56 test cases · 2 s / 256 MB per case