簡単 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 つずつ開いてみましょう。

ヒント 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 位になりましょう。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。