आसान 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 के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

हर कोडर का सबसे अच्छा पास हुआ समाधान। तेज़, कम मेमोरी वाले और बेहतर रेटिंग वाले समाधान ऊपर रहते हैं।

अभी कोई पास हुआ समाधान नहीं है। इसे हल करें और पहला स्थान पाएँ।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।