모든 챌린지
쉬움 0명 해결 정답률 0%

Payroll With Overtime

Compute each employee's weekly pay in cents with time and a half after 40 hours and double time after 50.

배우게 될 내용

  • Split hours into regular, overtime and double time bands
  • Compute pay in cents
  • Round half-cent amounts consistently

문제

번역본 보기

A small company runs payroll every week. Employee i worked hours[i] whole hours at an hourly rate of rates[i] cents.

  • The first 40 hours are paid at the normal rate.
  • Hours 41 to 50 are overtime, paid at 1.5 times the rate. The overtime part is rounded to the nearest cent, with half a cent rounding up.
  • Every hour beyond 50 is paid at double the rate.

Implement payroll_overtime(hours, rates).

Input

hours: The hours each employee worked this week.

rates: Each employee's hourly rate in cents, in the same order.

Output

Return each employee's pay in cents, in the same order as the input.

제약 조건

0 ≤ number of employees ≤ 1,000

0 ≤ hours ≤ 100

1 ≤ rate ≤ 100,000

예시

예시 1
입력:
hours = [38, 45]
rates = [2000, 2000]

예상 출력:
expected = [76000, 95000]
입력:
std::vector<long long> hours = {38, 45};
std::vector<long long> rates = {2000, 2000};

예상 출력:
std::vector<long long> expected = {76000, 95000};
입력:
long[] hours = new long[] {38, 45};
long[] rates = new long[] {2000, 2000};

예상 출력:
long[] expected = new long[] {76000, 95000};

설명

38 hours at 2000 is 76000. For 45 hours: 40 × 2000 = 80000 plus 5 overtime hours × 3000 = 15000, so 95000.

예시 2
입력:
hours = [53]
rates = [1525]

예상 출력:
expected = [93025]
입력:
std::vector<long long> hours = {53};
std::vector<long long> rates = {1525};

예상 출력:
std::vector<long long> expected = {93025};
입력:
long[] hours = new long[] {53};
long[] rates = new long[] {1525};

예상 출력:
long[] expected = new long[] {93025};

설명

40 × 1525 = 61000, overtime 10 × 1525 × 1.5 = 22875, and 3 double hours × 3050 = 9150: 93025.

접근 방법

먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.

힌트 1

Regular hours are min(hours, 40); work out the other two bands the same way.

힌트 2

1.5 × rate × hours equals 3 × rate × hours / 2, which keeps everything in integers.

힌트 3

Only the overtime part can produce half a cent.

예상 복잡도

O(n) time, O(n) extra space

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

코더마다 가장 좋은 통과 풀이입니다. 더 빠르고, 메모리를 덜 쓰고, 평가가 좋은 풀이가 위에 옵니다.

아직 통과한 풀이가 없습니다. 풀어서 1위를 차지하세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.