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

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter12: Event-driven Gui Programming, Multithreading, And Animation
Section: Chapter Questions
Problem 2GZ
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.
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
CMPTR
CMPTR
Computer Science
ISBN:
9781337681872
Author:
PINARD
Publisher:
Cengage
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning