🎁BACK-TO-SCHOOL DEAL. Subscribe Now to get 40% OFF at only 8.49 USD/month, only valid until Sep 30th, 2024

Question

Question
Description CS city hires M workers who drive water trucks. They spray water on the streets to clean them, and reduce the dust concentration. There are streets in CS city. The city has a dust control plan, which uses a task scheduler to generate a daily cleaning plan. This plan tells each worker what streets they are responsible for, and ideally all streets will be cleaned. For example, the plan tells worker A to clean street 0 to street , worker to clean streets . This plan will clean 7 streets. However, the task scheduler is buggy. Today it tells worker A to clean streets and tells worker B to clean streets [3, 5]. Someone realizes that two workers cleaned street 3 twice, and no one cleaned street 6. It's your job to write a program to automatically detect the task scheduler's bugs, and report how many streets are not cleaned in today's plan. Input Format The first line contains two integers . is the number of workers, and is the number of streets. The following lines are just the plan generated by task scheduler. Each line contains two integers , ]. It indicates that worker i should clean street to . Output Format One integer, representing how many streets have not been cleaned. Sample Input 27 Sample Input 27 03 35 Sample Output 1 Explanation Worker A cleans streets [0,3], and worker B cleans streets [3,5]. Street 6 is the only street that was not cleaned, so return 1. Input Constraints

Asked By EnchantedEcho88 at

Answered By Expert

Shawn

Expert · 2.1k answers · 2k people helped

Step 1/4

In this question, we have M workers and N streets to clean.

Each worker is assigned a set of streets in sequential order but due to a bug, sometimes the streets assigned get overlapped or some street gets left out.

We need to find how many streets got left out.

Step 2/4

First we take an array 'a' of size 2 to store the start and end street numbers of every worker.

Then we take an empty array named 'h' with all elements as 0.

We take input from user for the values of m and n.

Step 3/4

Now we take a for loop starting from 0 till m (number of workers)

Inside the loop, we input the values of start and end street number from the user into a[0] and a[1] respectively.

Now we take an inner loop starting from start street number or a[0], ending at end street number or a[1] (inclusive) and then for the values found inside this range, we change the corresponding value in the 'h' array from 0 to 1.

In other words we mark the streets covered (from start till end for every worker) by making their values as '1' in the 'h' array which initially contained '0'.

Step 4/4

in the end, we take another loop starting from 0 till the total number of streets.

we check if in the 'h' array there is an element whose value is still 0, that means that street hasn't been assigned to any worker.

if the value is 0, we count how many 0's are there in a variable count.

Final Answer

Final Code:

Input:

2 7

0 3

3 5

Output:

1

🧑‍🏫 More Questions

DIRECTIONS: Choose the BEST answer to each question and place your selection on the answer sheet 1. Which of the following transactions would require the use of the present value of an annuity due concept in order to calculate the present value of the asset obtained or liability owed at the date of incurrence? a. A capital lease is entered into with the initial lease payment due upon the signing of the lease agreement b. A capital lease is entered into with the initial lease payment due one month subse- quent to the signing of the lease agreement C. A ten-year 8% bond is issued onJanuary 2 with interest payable semiannually on July 1 and January 1 yielding 7%. d. A ten-year 8% bond is issued on January 2 with interest payable semiannually on July 1 and January 1 yielding 9%. 2. What best describes the time value of money? a. The interest rate charged on a loan b. Accounts receivable that are determined uncollectible c. An investment in a checking account. d. The relationship between time and money. 3. What is NOT a variable that is considered in interest computations? a. Principal. b. Interest rate. c. Assets. d. Time. Which factor would be greater-the present value of $1 for 10 periods at 8% per period or the future value of $1 for 10 periods at 8% per period? 4. Present value of $1 for 10 periods at 8% per period. a. b. c. d. Future value of $1 for 10 periods at 8% per period. The factors are the same. Need more information. Which table would you use to determine how much you would need to have deposited three years ago at 10% compounded annually in order to have $1,000 today? ra. Future value of 1 or present value of 1 b. Future value of an annuity due of 1 c. Future value of an ordinary annuity of 1 d. Present value of an ordinary annuity of 1 5. Which table would you use to determine how much must be deposited now in order to provide for 5 annual withdrawals at the beginning of each year, starting one year hence? a. Future value of an ordinary annuity of 1 b. Future value of an annuity due of 1 c. Present value of an annuity due of 1 d., Present value of an ordinary annuity of 1 6.

<p>Question 6 /12</p> <p><strong>A company receives $10,000 in cash for services yet to be performed.</strong></p> <p><strong>Using the accrual method, what's the correct entry to record the transaction?</strong></p> <p>(A) Debit cash $10,000, credit accounts receivable $10,000</p> <p>(B) Debit cash $10,000, credit sales revenue$1 0,000</p> <p>(C) Debit sales revenue $10,000, credit cash $10,000</p> <p>(D) Debit cash $10,000, credit unearned revenue $10,000</p> <p>(E) Debit cash $10,000, credit accounts payable $10,000</p> <p>&nbsp;</p> <p>Question 7 /12</p> <p><strong>Per company policy, tools with a purchase price greater than $1,000 are capitalized. What's the correct entry to record a tool purchase of $500?</strong></p> <p>(A) Debit tools expense $500, credit cash $500</p> <p>(B) Debit fixed asset $500, credit tools expense $500</p> <p>(C) Debit fixed asset $500, credit cash $500</p> <p>(D) Debit fixed asset $1,000, cred it cash $1,000</p> <p>(E) Debit tools expense $1,000, cred it cash $1,000</p> <p>&nbsp;</p> <p>Question 9 /12</p> <p><strong>A company performs $10,000 of services and issues an invoice to the customer. Using the accrual method. what's the cored entry to record the transactions?</strong></p> <p>(A) Debit unearned revenue $10,000, credit salles revenue $10,000</p> <p>(B) Debit accounts payable $10,000, credit sales revenue $10,000</p> <p>(C) Debit services expense $10,000, credit sales revenue $10,000</p> <p>(D) Debit cash $10,000, credit sales revenue $10,000</p> <p>(E) Debit accounts receivable $10,000, credit salles revenue $10,000</p>