Programming Challenge #7 [Beginner]


(oaktree) #1

Problem Statement

Daniel, an ambitious young programmer, decides to go to a party one afternoon. However, having not partied often, Daniel has a bad tolerance for liqour.

Given that it takes an integer n minutes for Daniel to metabolize the alcohol in one drink, how many hours after drinking his last of d drinks can Daniel safely drive himself home? Note: Assume that he does not start metabolizing until he has drank his last drink.

Daniel’s friend Matt says that Daniel can metabolize twice as fast is he is doing jumping jacks. If Daniel decides to do jumping jacks for j minutes, hour many hours does he have to wait before leaving the party?


0 < n <= 120
0 <= d <= 12
0 <= j <= n * d / 2

Input: t, the number of test cases. n, d, j, separated by spaces, in that order, for t following lines.

Output: The number of hours, to the nearest hour, Daniel must wait before coming home.


Sample Input

45 4 30
35 7 12

Sample Output



Test Case 0: To metabolize 4 drinks at a rate of one drink every 45 minutes, it would take Daniel 3 hours to sober up. Daniel does jumping jacks for 30 minutes, though, which shaves an hour off that time. Thus, it takes Daniel 2.5 hours to sober up. Rounding to the nearest hour, it takes Daniel 3 hours to go home.

Test Case 1: To regularly deal with 7 drinks at 35 min/drink, it would take Daniel 245 minutes. Twelve minutes of jumping jacks shaves off 24 minutes from that. In the end, it would take Daniel 233 minutes in total, or 4 hours, to be ready to drive.

Copyright © oaktree, 2016

I’m eager to see what you guys do! It’s an easy one, but it’s the first one I’ve actually made. I’ll have my solution up soon.


hey @oaktree, nice challenge! My solution will be up shortly, however, I have a question… When you say that Daniel does jumping jacks for 12 minutes which shaves off 24 minutes from the total metabolization time, shouldn’t you take 24 min from 245 min instead of the actual 12, making it 221?


(Ne0_) #3

But you have to add another 12 minutes because he needed that time to do jumping jacks. Therefore, the reduction by 12 is correct.


Oooh! right, that makes sense! Thanks for the answer @Neo



from __future__ import division

def sober_up():
    n,d,j = raw_input('[*] Input > ').split()
    met = int(n) * int(d) - int(j)
    met = met / 60

t = int(raw_input('[*] Input the number of test cases > '))
for i in range (0,t):

It’s slightly different from the instructions given, but it get’s the job done :smile:

(oaktree) #6

@n3xUs: You take 24 minutes off, but he still has to do 12 minutes of work, so you have to add 12 back. @Neo gets it!

(oaktree) #7

Official Solution

#include <iostream>
#include <string>

int main() {
	int t,n,d,j;
	std::cin >> t;

	while (t-- > 0) {
		std::cin >> n >> d >> j;
		std::cout << ((n*d - j)/60 + ( (n*d - j) % 60 >= 30 ? 1 : 0) ) << std::endl;
	return 0;

This problem was pretty easy, so I’ll be releasing a harder version soon.

(oaktree) #8

This topic was automatically closed after 30 days. New replies are no longer allowed.