formation 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 to the problem. Make sure both test cases return correct answers. Output Format The output consists of a single integer n, which is the minimum margin in milliseconds that would make it such that at least R% of the button presses would be graded as Perfects. If no such margin exists, print "It's impossible!" (without quotes). Sample Input 0 5 40 5 87

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

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 to the problem. Make sure both test cases return correct answers.

Output Format

The output consists of a single integer n, which is the minimum margin in milliseconds that would make it such that at least R% of the button presses would be graded as Perfects. If no such margin exists, print "It's impossible!" (without quotes).

Sample Input 0
5 40
5 87
14 -1
22 271
25 628
46 -1

Sample Output 0
249

Explanation 0
A 40% accuracy means that the two most accurate notes must be considered perfect. The error margin of the first note (5, 87) is |87 - 5| = 82 and the error margin of the third note (22, 271) is |271 - 22| = 249. Other notes would have higher margins, and the second and fifth notes are both Misses, therefore the minimum margin such that 40% of the notes may be considered perfect is the error margin of the third note, 249.

Sample Input 1
6 62
11 251
28 261
66 -1
73 -1
80 666
86 929

Sample Output 1
843

Explanation 1
A 62% accuracy means that out of six notes, the four most accurate notes must be considered perfect. Two notes are Misses, the third and fourth notes. This means that the highest error margin among the other four notes will be the minimum error margin such that 62% of the six notes would be considered Perfect. The sixth note has the highest error margin of |929 - 86| = 843.

The actual code

"""
    n - number of notes
    r - target accuracy date
    times contains:
        t_i (actual time in ms start of the chart)
        p_i (actual time the player pressed the button in ms)
"""
def solve(n,r,times):
    # compute for and return answer here
    
def main():
    n, r = list(map(int,input().strip().split(" ")))
    times = [list(map(int,input().strip().split(" "))) for i in range(n)]
    
    print(solve(n,r,times))

if __name__ == "__main__":
    main()

In 1987, often credited as the first rhythm game PaRappa the Rapper introduced the core mechanic of rhythm
games, repeating a preprogrammed pattern within an allowable amount of time. A decade later, Beatmania
would introduce more modern mechanics, like scoring based on how accurate one's button presses are to the
actual time they need to be pressed, which would become a staple mechanic among all classic rhythm games.
When a note appears on screen in a rhythm game, players would need to press the button that corresponds
to the note at a specific time. This is usually indicated by the note slowly approaching a note bar. The button
press is then graded depending on how close to the bar the note is when the button is pressed, which
corresponds to how many milliseconds the button press is off from perfect timing. If the button press is within
n milliseconds of the note hitting the note bar, where n is a small time limit, the button press is given a
Perfect grade. Suppose it is within m milliseconds, where m is greater than n but is still within an allowable
limit. In that case, the button press is considered Good. Outside of m, then the button press is considered a
miss. This is repeated for all the notes in a chart; a chart corresponds to a level or a song that contains a set of
notes.
Consider the following image:
The white bar is the note bar, while the red rectangle is the note. Imagine this red rectangle has been
approaching the note bar from the top of the screen. The note is currently right on top of the note bar. If the
player presses the button now, it is considered a Perfect. However, it would still be considered a perfect if the
button is pressed while the red rectangle (the note) is within the green area (the Perfect area). If the button is
pressed while the note is outside the Perfect area, but within the blue area (the good area), then the button
press is given a grade of Good. Finally, if the button is pressed while the note is outside the Perfect and Good
areas, then the button press is a Miss.
Transcribed Image Text:In 1987, often credited as the first rhythm game PaRappa the Rapper introduced the core mechanic of rhythm games, repeating a preprogrammed pattern within an allowable amount of time. A decade later, Beatmania would introduce more modern mechanics, like scoring based on how accurate one's button presses are to the actual time they need to be pressed, which would become a staple mechanic among all classic rhythm games. When a note appears on screen in a rhythm game, players would need to press the button that corresponds to the note at a specific time. This is usually indicated by the note slowly approaching a note bar. The button press is then graded depending on how close to the bar the note is when the button is pressed, which corresponds to how many milliseconds the button press is off from perfect timing. If the button press is within n milliseconds of the note hitting the note bar, where n is a small time limit, the button press is given a Perfect grade. Suppose it is within m milliseconds, where m is greater than n but is still within an allowable limit. In that case, the button press is considered Good. Outside of m, then the button press is considered a miss. This is repeated for all the notes in a chart; a chart corresponds to a level or a song that contains a set of notes. Consider the following image: The white bar is the note bar, while the red rectangle is the note. Imagine this red rectangle has been approaching the note bar from the top of the screen. The note is currently right on top of the note bar. If the player presses the button now, it is considered a Perfect. However, it would still be considered a perfect if the button is pressed while the red rectangle (the note) is within the green area (the Perfect area). If the button is pressed while the note is outside the Perfect area, but within the blue area (the good area), then the button press is given a grade of Good. Finally, if the button is pressed while the note is outside the Perfect and Good areas, then the button press is a Miss.
With the advent of Al, a more friendly rhythm game is now being developed, which takes your performance
from the previous chart you played and uses it to adjust its Perfect and Good timing windows. This friendly
rhythm game adjusts its Perfect window such that R% of your button presses from the previous played chart
will be considered perfect.
Your task is to write a program that would calculate the minimum timing margin n in milliseconds that would
make it such that this property holds, given the actual times in milliseconds players pressed the
corresponding button to the notes in a chart.
Input Format
The first line of the input contains a two space-separated integers N and R, which indicates the number of
notes in the chart and the target accuracy rate.
N lines follow, each containing a pair of space-separated integers t; and p₁, where t; is the actual time in
milliseconds from the start of the chart the ith button should be pressed, and p; is the actual time the player
pressed the ith button in milliseconds from the start of the chart.
Note that if a button press is graded a "Miss", then it's p; value would be -1.
Constraints
1 ≤ N≤ 105
0≤R≤ 100
0 ≤ti, Pi≤ 10¹2 V pi = -1 for all 1 ≤ i ≤ N
ti < ti+1 for all 1 < i < N
(Pi -1^ Pi+1 # −1) ⇒ Pi < Pi+1 for all 1 < i < N
‡
Transcribed Image Text:With the advent of Al, a more friendly rhythm game is now being developed, which takes your performance from the previous chart you played and uses it to adjust its Perfect and Good timing windows. This friendly rhythm game adjusts its Perfect window such that R% of your button presses from the previous played chart will be considered perfect. Your task is to write a program that would calculate the minimum timing margin n in milliseconds that would make it such that this property holds, given the actual times in milliseconds players pressed the corresponding button to the notes in a chart. Input Format The first line of the input contains a two space-separated integers N and R, which indicates the number of notes in the chart and the target accuracy rate. N lines follow, each containing a pair of space-separated integers t; and p₁, where t; is the actual time in milliseconds from the start of the chart the ith button should be pressed, and p; is the actual time the player pressed the ith button in milliseconds from the start of the chart. Note that if a button press is graded a "Miss", then it's p; value would be -1. Constraints 1 ≤ N≤ 105 0≤R≤ 100 0 ≤ti, Pi≤ 10¹2 V pi = -1 for all 1 ≤ i ≤ N ti < ti+1 for all 1 < i < N (Pi -1^ Pi+1 # −1) ⇒ Pi < Pi+1 for all 1 < i < N ‡
Expert Solution
steps

Step by step

Solved in 3 steps with 1 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