Picking Tickets Consider an array of n ticket prices, tickets. We define a number, m, to...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Picking Tickets Consider an array of n ticket prices, tickets. We define a number, m, to be the size of some subsequence, s, of tickets where each element covers an unbroken range of integers; that is to say, if you were to sort the elements in s, the difference between any elements j andj + 1 would be either 0 or 1. For example, tickets = [8, 5, 4, 8, 4] gives us sorted subsequences][4, 4, 5) and (8, 8); these subsequences have m values of 3 and 2, respectively. Complete the maxTickets function in the editor below. It has one parameter: an array of integers, tickets. The function must return an integer denoting the maximum possible value of m. Input Format Locked stub code in the editor reads the following input from stdin and passes it to the function: The first line contains an integer, n, denoting the number of elements in tickets. Each line of the n subsequent lines (where 0 si<n) contains an integer describing tickets. Constraints Osn≤2× 10% Ask me anything J a Constraints 0≤n≤2 x 106 0 ≤ tickets, ≤ 2 x 106 Output Format Print the maximum value of m (i.e., the size of the largest unbroken sequence of sorted consecutive integers whose adjacent elements have a maximum absolute difference of 1). Sample Input 0 4 13 2 3 Sample Output 0 3 Explanation 0 tickets=14, 13, 2, 31 There are two subsequences of tickets that contain consecutively Ask me anything 0 a rint the maximum value of m (i.e., the size of the largest unt equence of sorted consecutive integers whose adjacent elem a maximum absolute difference of 1). Sample Input 0 4 4 13 23 Sample Output 0 3 Explanation 0 tickets = [4, 13, 2, 3] There are two subsequences of tickets that contain consecutively numbered integers: (2, 3, 4) and (13). These subsequences have m values of 3 and 1, respectively. We return the maximum value of m. which is 3. Ask me anything 0 1> #include → 1234 56 using namespace std; 6 ▼/* 7 8 9 10 11 12 Complete the function below. int maxTickets (vector <int> tickets) { tickets) } Picking Tickets Consider an array of n ticket prices, tickets. We define a number, m, to be the size of some subsequence, s, of tickets where each element covers an unbroken range of integers; that is to say, if you were to sort the elements in s, the difference between any elements j andj + 1 would be either 0 or 1. For example, tickets = [8, 5, 4, 8, 4] gives us sorted subsequences][4, 4, 5) and (8, 8); these subsequences have m values of 3 and 2, respectively. Complete the maxTickets function in the editor below. It has one parameter: an array of integers, tickets. The function must return an integer denoting the maximum possible value of m. Input Format Locked stub code in the editor reads the following input from stdin and passes it to the function: The first line contains an integer, n, denoting the number of elements in tickets. Each line of the n subsequent lines (where 0 si<n) contains an integer describing tickets. Constraints Osn≤2× 10% Ask me anything J a Constraints 0≤n≤2 x 106 0 ≤ tickets, ≤ 2 x 106 Output Format Print the maximum value of m (i.e., the size of the largest unbroken sequence of sorted consecutive integers whose adjacent elements have a maximum absolute difference of 1). Sample Input 0 4 13 2 3 Sample Output 0 3 Explanation 0 tickets=14, 13, 2, 31 There are two subsequences of tickets that contain consecutively Ask me anything 0 a rint the maximum value of m (i.e., the size of the largest unt equence of sorted consecutive integers whose adjacent elem a maximum absolute difference of 1). Sample Input 0 4 4 13 23 Sample Output 0 3 Explanation 0 tickets = [4, 13, 2, 3] There are two subsequences of tickets that contain consecutively numbered integers: (2, 3, 4) and (13). These subsequences have m values of 3 and 1, respectively. We return the maximum value of m. which is 3. Ask me anything 0 1> #include → 1234 56 using namespace std; 6 ▼/* 7 8 9 10 11 12 Complete the function below. int maxTickets (vector <int> tickets) { tickets) }
Expert Answer:
Answer rating: 100% (QA)
The required c function implementation is as follows Function to find the maximum size of a subseque... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
question answer c and E . can any one help me why 95% lower limit and upper limit not match with excel data as well as correlation coefficient is not matching in answer E. X 250 270 290 310 330 350...
-
This is in C programming. Please help change the program from round robin to shortest remaining time next. Link for google drive:...
-
C programming Question. please help me
-
Repeat the analysis of problem 14.7, but this time focus on the Facebook call and put options in Figure 14.1 that have a strike price of $87.50. If you use put-call parity to find the price of...
-
If risk is to be analyzed in a qualitative way, place the following investment decisions in order from the lowest risk to the highest risk: a. New equipment b. New market c. Repair of old machinery...
-
Ellis Manufacturing Company makes a product that sells for $74 per unit. Manufacturing costs for the product amount to $26 per unit variable, and $80,000 fixed. During the current accounting period,...
-
When conducting an incremental analysis, what step must always be taken immediately prior to beginning the pairwise comparisons? a. Order the alternatives from highest to lowest initial investment b....
-
An initial solution has been given to the following workcenter layout problem. Given the flows described and a cost of $ 2.00 per unit per foot, compute the total cost for the layout. Each location...
-
You will be taking over the vending machine business at UNCC from Tony. You are selling 20-ounce bottles of Dasani bottled water for $1.25, and Tony will give you a large stock of Dasani to get you...
-
Exercise 14-17 (Algorithmic) (LO. 1, 4) Prance, Inc., earned pretax book net income of $1,925,000 in 2020. Prance acquired a depreciable asset in 2020, and first-year tax depreciation exceeded book...
-
Utilitarians would say that jeopardizing motorists does not by itself make Ford's action morally objectionable. The only morally relevant matter is whether Ford gave equal consideration to the...
-
Solve the equation -1223-622-6z Answer: z = answers as integers or reduced fractions, separated by commas. Give your
-
As a construction company "Conet" operating in Melbourne Victoria, write a thorough formal to a labour hire agency enquiring about fees and charges for 1general labour hire or a group of labours for...
-
Summarize an article about a publicly traded company that has been cited, fined, or charged with fraud (or other issues) due to improper accounting of contingent liabilities. Include a link to the...
-
Use this lecture outline/guide to add notes from your reading under each topic. Include references to examples, exercises and problems that illustrate the concept. Define each of the following terms:...
-
Solis & Co., a national accounting firm, was hired to conduct an audit of Huntington Corp.'s financial statements. Solis & Co. negligently conducted the audit and failed to discover $1 million in...
-
Compute the length of the curve r(t) = 4ti + 9tj + (3t 8)k over the interval 0 t 2. - (Use decimal notation. Give your answer to three decimal places.) S =
-
The Pletcher Transportation Company uses a responsibility reporting system to measure the performance of its three investment centers: Planes, Taxis, and Limos. Segment performance is measured using...
-
A Toeplitz matrix is an n n matrix A = (a ij ) such that a ij = a i - 1 . j - 1 for i = 2, 3, . . . , n and j = 2, 3 , . . . , n. a. Is the sum of two Toeplitz matrices necessarily Toeplitz? What...
-
Prove that 2 i=1 + N
-
There are two types of professional wrestlers: "babyfaces" ("good guys") and "heels" ("bad guys"). Between any pair of professional wrestlers, there may or may not be a rivalry. Suppose we have n...
-
R&B Beverages, Inc., provides a complete line of beer, wine, and soft drink products for distribution through retail outlets in central Iowa. Unit price data for 2008 and 2011 and quantities sold in...
-
A large manufacturer purchases an identical component from three independent suppliers that differ in unit price and quantity supplied. The relevant data for 2009 and 2011 are given here. a. Compute...
-
Data on quantities of three items sold in 1997 and 2011 are given here along with the sales prices of the items in 1997. Compute a weighted aggregate quantity index for 2011. Quantity Sold Item 1997...
Study smarter with the SolutionInn App