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 must be as small as possible (nlogn or n at best, no n^2). Apply a greedy algorithm in the problem. Make sure the code can pass all the test cases mentioned plus could also work for larger values and unique cases.   The actual Incompelete code- """ This function solves a test case. Parameters: n      : int        - number of duties available t      : int        - time to do duties in minutes duties : array-like - a 3-tuple of string values in the format (name, wait time,                       completion time) Returns: A string containing the answer or "I need to find friends."              """ def solve(n,t,duties):     # TODO     pass n, t = list(map(int,input().split(" "))) duties = [] for i in range(n):     name = input()     w,c = list(map(int,input().split(" ")))     duties.append([name,w,c]) print(solve(n,t,duties))

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 must be as small as possible (nlogn or n at best, no n^2). Apply a greedy algorithm in the problem. Make sure the code can pass all the test cases mentioned plus could also work for larger values and unique cases.

 

The actual Incompelete code-

"""
This function solves a test case.

Parameters:
n      : int        - number of duties available
t      : int        - time to do duties in minutes
duties : array-like - a 3-tuple of string values in the format (name, wait time,
                      completion time)

Returns:
A string containing the answer or "I need to find friends."             
"""
def solve(n,t,duties):
    # TODO
    pass

n, t = list(map(int,input().split(" ")))
duties = []

for i in range(n):
    name = input()
    w,c = list(map(int,input().split(" ")))
    duties.append([name,w,c])


print(solve(n,t,duties))

 

 

 

 

Sample Input 0
3 10
Brayflox's Longstop
1 2
Sastasha
32
Urth's Fount
66
Sample Output 0
3
Sample Input 1
32
Copperbell Mines
13 14
Thornmarch (Hard)
227 228
The Aurum Vale
7 10
Sample Output 1
2
Sample Input 2
42
Haukke Manor
117 111
Thornmarch (Hard)
118 115
The World of Darkness
114 113
The Aery
114 110
Sample Output 2
I need to find friends.
Transcribed Image Text:Sample Input 0 3 10 Brayflox's Longstop 1 2 Sastasha 32 Urth's Fount 66 Sample Output 0 3 Sample Input 1 32 Copperbell Mines 13 14 Thornmarch (Hard) 227 228 The Aurum Vale 7 10 Sample Output 1 2 Sample Input 2 42 Haukke Manor 117 111 Thornmarch (Hard) 118 115 The World of Darkness 114 113 The Aery 114 110 Sample Output 2 I need to find friends.
Did you know that the critically acclaimed MMORPG Final Fantasy XIV has a free trial and includes the entirety
of A Realm Reborn AND the award-winning Heavensward expansion up to level 60 with no restrictions on
playtime? Sign up, and enjoy Eorzea today!
Despite the critical acclaim, however, one disadvantage for people without friends is that they have to resort
to the duty finder to do co-op duties, which are required for the main scenario quest.
To simplify this scenario, assume that for each possible duty, we know exactly two values to the most precise
degree: the time W; it will take to find a party of other players for the duty and C₂ the time it will take to
complete the duty successfully. All time is in seconds.
You have exactly I minutes before your next class, and you wish to complete as many duties as possible. You
also do not want to repeat any duties you have completed in this period. Can you identify the set of duties to
queue for and to complete?
Input Format
Each test case begins with two space-separated integers N and T, indicating the number of available duties
and the time (in minutes) you will have to complete as many duties as possible.
2N lines follow. The first line contains the name of the duty, which may consist of any ASCII values that can be
shown on the screen. The second line contains two space-separated integers W₂ and C₂, indicating the duty's
waiting time and completion time (in seconds).
Constraints
1≤N ≤2-105
1 ≤T, W₁, C ≤ 10⁹
Output Format
Output a single integer indicating the total number of duties that can be completed within the time limit. If no
duties can be completed, print "I need to find friends." (without quotes)
Transcribed Image Text:Did you know that the critically acclaimed MMORPG Final Fantasy XIV has a free trial and includes the entirety of A Realm Reborn AND the award-winning Heavensward expansion up to level 60 with no restrictions on playtime? Sign up, and enjoy Eorzea today! Despite the critical acclaim, however, one disadvantage for people without friends is that they have to resort to the duty finder to do co-op duties, which are required for the main scenario quest. To simplify this scenario, assume that for each possible duty, we know exactly two values to the most precise degree: the time W; it will take to find a party of other players for the duty and C₂ the time it will take to complete the duty successfully. All time is in seconds. You have exactly I minutes before your next class, and you wish to complete as many duties as possible. You also do not want to repeat any duties you have completed in this period. Can you identify the set of duties to queue for and to complete? Input Format Each test case begins with two space-separated integers N and T, indicating the number of available duties and the time (in minutes) you will have to complete as many duties as possible. 2N lines follow. The first line contains the name of the duty, which may consist of any ASCII values that can be shown on the screen. The second line contains two space-separated integers W₂ and C₂, indicating the duty's waiting time and completion time (in seconds). Constraints 1≤N ≤2-105 1 ≤T, W₁, C ≤ 10⁹ Output Format Output a single integer indicating the total number of duties that can be completed within the time limit. If no duties can be completed, print "I need to find friends." (without quotes)
Expert Solution
steps

Step by step

Solved in 3 steps

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
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