Information is present in the screenshot and below. Based on that need help in solving the code for this problem in python. The time complexity has to be as less as possible (nlogn or n at best, no n^2). Apply greedy algorithm in the problem. Make sure both test cases return correct answers. Output Format Output consists of one line containing the maximum revenue Elsa and Lucy and attain during one day. Sample Input 0 3 5 0 4 0 7 4 5 Sample Output 0 10 Explanation 0 Lucy and Elsa can attend the first event from 0 to 4, then instantly teleport to the third event, which goes from 4 to 5. Charging 5 gold per event, they can earn 10 gold. Sample Input 1 5 8 0 8 1 7 2 6 3 5 4 5 Sample Output 1 8 The actual code def solve(n,c,vals):   # TODO: Compute and return answer here   pass n, c = list(map(int,input().strip().split(" "))) vals = [list(map(int,input().strip().split(" "))) for i in range(n)] print("{}".format(solve(n,c,vals)))

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Information is present in the screenshot and below. Based on that need help in solving the code for this problem in python. The time complexity has to be as less as possible (nlogn or n at best, no n^2). Apply greedy algorithm in the problem. Make sure both test cases return correct answers.

Output Format
Output consists of one line containing the maximum revenue Elsa and Lucy and attain during one day.

Sample Input 0
3 5
0 4
0 7
4 5

Sample Output 0
10

Explanation 0
Lucy and Elsa can attend the first event from 0 to 4, then instantly teleport to the third event, which goes from 4 to 5. Charging 5 gold per event, they can earn 10 gold.

Sample Input 1
5 8
0 8
1 7
2 6
3 5
4 5

Sample Output 1
8

The actual code

def solve(n,c,vals):
  # TODO: Compute and return answer here
  pass

n, c = list(map(int,input().strip().split(" ")))
vals = [list(map(int,input().strip().split(" "))) for i in range(n)]
print("{}".format(solve(n,c,vals)))

Lucy and Elsa are best friends who live in Trollskull Alley in the City of Waterdeep. They are acquainted with a
member of the Zhentarim, a local faction in Waterdeep. This member is named Strygwyr.
One day, Lucy's close friend, Jarlaxle Baenre, asked her for a favor. She has to drop an expose on the
Cassalanter family in the offices of the Waterdeep Enchiridion, but must do so discreetly. She asks her BFF
Elsa for help. It just so happens, Elsa is a sorcerer and can conjure an illusion that makes Lucy look like
someone else. She decided on a whim to look like her acquaintance, Strygwyr, but with glasses, and proceeds
to do Jarlaxle's favor under the guise of a bespectacled Strygwyr.
Unfortunately (or fortunately), she caught someone's eye, but not of murderous individuals. Apprently, glasses
makes Strygwyr look like an absolute heartthrob, and the fair maidens of Waterdeep could only do so much to
resist the charms of the bespectacled young man. Lucy notices this and decides to turn this into a business
opportunity.
She proceeds to make appearances around town under the guise, with Elsa's assistance and approval. This
happens until she, taking the moniker "Ben", is now a well-known and well-loved face around Waterdeep.
She sends her friend's owl, Blathers, on a reconaissance mission to determine the waking patterns of the fair
maiden fangirls of Waterdeep. She notices that the fangirls are actively awaiting their heartthrob's appearance
on the streets during N distinct times of day. Lucy and Elsa decide to begin charging a flat price for "Ben"s
celebrity appearances, and, obviously, they would like to maximize their revenue.
Given the N time periods during the day where the fangirls of Waterdeep are active, and the flat charge of C
gold pieces for one appearance, determine the maximum revenue Elsa and Lucy can attain during one day
masquerading as Ben in Waterdeep. Assume that Elsa can teleport them to the next appearance instantly, but
she can not duplicate "Ben" or conjure a second "Ben" illusion, so they cannot be at two places at once.
Input Format
Input consists of one test case, beginning with a line containing two space-separated integers N and C.
N lines follow, each containing two space-separated integers S; and E₁, which indicate the start and end
time (in seconds from midnight of that day) for each fangirl congregation's "active period" in which Lucy and
Elsa can have "Ben" appear, charging a flat rate of C for the appearance.
Constraints
0 ≤N ≤ 2.105
0 ≤C ≤ 10⁹
0 ≤ Si < Ei ≤ 86400
Transcribed Image Text:Lucy and Elsa are best friends who live in Trollskull Alley in the City of Waterdeep. They are acquainted with a member of the Zhentarim, a local faction in Waterdeep. This member is named Strygwyr. One day, Lucy's close friend, Jarlaxle Baenre, asked her for a favor. She has to drop an expose on the Cassalanter family in the offices of the Waterdeep Enchiridion, but must do so discreetly. She asks her BFF Elsa for help. It just so happens, Elsa is a sorcerer and can conjure an illusion that makes Lucy look like someone else. She decided on a whim to look like her acquaintance, Strygwyr, but with glasses, and proceeds to do Jarlaxle's favor under the guise of a bespectacled Strygwyr. Unfortunately (or fortunately), she caught someone's eye, but not of murderous individuals. Apprently, glasses makes Strygwyr look like an absolute heartthrob, and the fair maidens of Waterdeep could only do so much to resist the charms of the bespectacled young man. Lucy notices this and decides to turn this into a business opportunity. She proceeds to make appearances around town under the guise, with Elsa's assistance and approval. This happens until she, taking the moniker "Ben", is now a well-known and well-loved face around Waterdeep. She sends her friend's owl, Blathers, on a reconaissance mission to determine the waking patterns of the fair maiden fangirls of Waterdeep. She notices that the fangirls are actively awaiting their heartthrob's appearance on the streets during N distinct times of day. Lucy and Elsa decide to begin charging a flat price for "Ben"s celebrity appearances, and, obviously, they would like to maximize their revenue. Given the N time periods during the day where the fangirls of Waterdeep are active, and the flat charge of C gold pieces for one appearance, determine the maximum revenue Elsa and Lucy can attain during one day masquerading as Ben in Waterdeep. Assume that Elsa can teleport them to the next appearance instantly, but she can not duplicate "Ben" or conjure a second "Ben" illusion, so they cannot be at two places at once. Input Format Input consists of one test case, beginning with a line containing two space-separated integers N and C. N lines follow, each containing two space-separated integers S; and E₁, which indicate the start and end time (in seconds from midnight of that day) for each fangirl congregation's "active period" in which Lucy and Elsa can have "Ben" appear, charging a flat rate of C for the appearance. Constraints 0 ≤N ≤ 2.105 0 ≤C ≤ 10⁹ 0 ≤ Si < Ei ≤ 86400
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education