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 If it is possible to cover the entire facade, output a single line containing the maximum number of party members who can leave the

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

If it is possible to cover the entire facade, output a single line containing the maximum number of party members who can leave their posts and confront Barlow as described in the problem statement.

If there is no group of party members who can cover the entire facade, output one line containing "'Salem's Lot is doomed." without quotes.

See the sample input for an example.

Sample Input 0
10 3
1 4
5 10
1 8

Sample Output 0
1

Explanation 0
Person 0 can cover the 1 to 4 range.
Person 1 can cover the 5 to 10 range.
Since 2 people are enough to hold the facade, they can send 1 person inside.

Sample Input 1
10 3
1 4
5 9
1 8

Sample Output 1
'Salem's Lot is doomed.

Explanation 1
Nobody in the party can cover the last meter of the facade, therefore 'Salem's Lot is doomed.

The actual code

def solve(L,n,coverage):
    # compute and return answer

L,n = list(map(int,input().rstrip().split(" ")))
coverage = [list(map(int,input().rstrip().split(" "))) for i in range(n)]
print(solve(L,n,coverage))

Father Callaghan has escaped 'Salem's Lot by sunrise. He had failed to save the town. The vampires had won.
Two years have passed. 'Salem's Lot is still infested with vampires, led by the insidious Kurt Barlow. However,
Father Callaghan has brought some backup. The former citizens of 'Salem's Lot who also barely escaped have
now joined him in taking back their home.
As they enter the town with their specialized vampire-killing gear, they now cornered the last of the vampires
in the fences of the Marsten house. The house is backed up against a hill so they can't escape through the
back. The only escape is through the facade of the house.
The house's facade extends L meters. Father Callaghan and his companions come up to a total of N people
that can barricade the facade. Each person can cover a specific part of the facade. They have decided that as
many of them as possible must enter the house to confront Barlow. This means they have to select as few of
them as needed to cover the entire facade (which means at least one person must be guarding all positions
from 1 to L) or else the vampires may be able to flank them.
Input Format
Input consists of one test case beginning with a line with two space-separated integers L and N.
L is the total length of the facade of the house.
N is the number of people in Callaghan's party.
N lines follow, the ith of which contains two integers A; and B; indicating the left and right bounds the ith
party member can cover respectively.
Constraints
2<L ≤ 10¹8
1≤ N≤ 3.105
1 ≤ A ≤ B ≤L
Transcribed Image Text:Father Callaghan has escaped 'Salem's Lot by sunrise. He had failed to save the town. The vampires had won. Two years have passed. 'Salem's Lot is still infested with vampires, led by the insidious Kurt Barlow. However, Father Callaghan has brought some backup. The former citizens of 'Salem's Lot who also barely escaped have now joined him in taking back their home. As they enter the town with their specialized vampire-killing gear, they now cornered the last of the vampires in the fences of the Marsten house. The house is backed up against a hill so they can't escape through the back. The only escape is through the facade of the house. The house's facade extends L meters. Father Callaghan and his companions come up to a total of N people that can barricade the facade. Each person can cover a specific part of the facade. They have decided that as many of them as possible must enter the house to confront Barlow. This means they have to select as few of them as needed to cover the entire facade (which means at least one person must be guarding all positions from 1 to L) or else the vampires may be able to flank them. Input Format Input consists of one test case beginning with a line with two space-separated integers L and N. L is the total length of the facade of the house. N is the number of people in Callaghan's party. N lines follow, the ith of which contains two integers A; and B; indicating the left and right bounds the ith party member can cover respectively. Constraints 2<L ≤ 10¹8 1≤ N≤ 3.105 1 ≤ A ≤ B ≤L
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Eight puzzle problem
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
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