Dễ 0 đã giải Tỷ lệ chấp nhận 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.

Bạn sẽ học được gì

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

Đề bài

Xem bản dịch

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.

Ràng buộc

0 ≤ number of employees ≤ 1,000

0 ≤ hours ≤ 100

1 ≤ rate ≤ 100,000

Ví dụ

Ví dụ 1
Đầu vào:
hours = [38, 45]
rates = [2000, 2000]

Kết quả mong đợi:
expected = [76000, 95000]
Đầu vào:
std::vector<long long> hours = {38, 45};
std::vector<long long> rates = {2000, 2000};

Kết quả mong đợi:
std::vector<long long> expected = {76000, 95000};
Đầu vào:
long[] hours = new long[] {38, 45};
long[] rates = new long[] {2000, 2000};

Kết quả mong đợi:
long[] expected = new long[] {76000, 95000};

Giải thích

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

Ví dụ 2
Đầu vào:
hours = [53]
rates = [1525]

Kết quả mong đợi:
expected = [93025]
Đầu vào:
std::vector<long long> hours = {53};
std::vector<long long> rates = {1525};

Kết quả mong đợi:
std::vector<long long> expected = {93025};
Đầu vào:
long[] hours = new long[] {53};
long[] rates = new long[] {1525};

Kết quả mong đợi:
long[] expected = new long[] {93025};

Giải thích

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

Hướng tiếp cận

Hãy tự thử trước, sau đó mở từng gợi ý một.

Gợi ý 1

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

Gợi ý 2

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

Gợi ý 3

Only the overtime part can produce half a cent.

Độ phức tạp mong đợi

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

Tham khảo

Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.

Lời giải đạt tốt nhất của mỗi người. Lời giải nhanh hơn, tốn ít bộ nhớ hơn và được đánh giá cao hơn sẽ đứng trên.

Chưa có lời giải nào đạt. Giải bài này để giành hạng nhất.

Học hỏi từ người khác

Giải pháp cộng đồng

Chưa có giải pháp nào được chia sẻ. Hãy giải thử thách này để đăng giải pháp đầu tiên.