Overtime Pay

Medium · rating 1200 · Math, Implementation

An hourly worker is paid rate cents per hour for up to 40 hours, and time-and-a-half (1.5× the rate) for every hour beyond 40. Read two space-separated integers hours rate (with rate even) and print the total weekly pay in cents.

Constraints: 0 ≤ hours ≤ 168, 0 ≤ rate ≤ 105, rate even

Editorial

Approach

Split the hours at 40. Everything up to 40 pays the flat rate; each hour above 40 pays 1.5×, i.e. rate × 3 ÷ 2. Because the rate is even, that half-rate is exact in integer arithmetic.

hours, rate = map(int, input().split())
if hours <= 40:
    pay = hours * rate
else:
    pay = 40 * rate + (hours - 40) * rate * 3 // 2
print(pay)

Complexity

Time: O(1). Space: O(1).

Related problems

Open Overtime Pay in Code Arena →