# 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?

# Constraints

`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.

# Example

## Sample Input

``````2
45 4 30
35 7 12
``````

## Sample Output

``````3
4
``````

## Explanation

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.

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.

4 Likes

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?

Thanks

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

1 Like

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

#Python#

``````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):
sober_up()

``````

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

2 Likes

@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!

1 Like

# 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.

2 Likes

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