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 Output consists of either a single integer n, where n is the maximum number of problems that can be solved within the given time limit T, or "This exam is impossible!" (without quotes) if no problem can be solved within the given time limit T. Sample Input 0 5 29 3 8 7 9 7 2 6 6 7 4 Sample Output 0 4 Explanation 0 You can finish the first 4 problems, which will take 3+7+7+6=23 seconds. Attempting the fifth problem will result in 23+7=30 seconds, which is greater than T=29. Sample Input 1 6 5 6 6 7 10 9 4 9 11 10 10 10 0 Sample Output 1 This exam is impossible! Explanation 1 None of the problems have t_i <= T=5, so it is impossible to finish even a single problem. The actual code def solve(n,t,problems): # compute and return answer here def main(): n,t = list(map(int,input().strip().split(' '))) problems = [tuple(map(int,input().strip().split(" "))) for i in range(n)] print(solve(n,t,problems)) if __name__ == "__main__":
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
Output Format
Output consists of either a single integer n, where n is the maximum number of problems that can be solved within the given time limit T, or "This exam is impossible!" (without quotes) if no problem can be solved within the given time limit T.
Sample Input 0
5 29
3 8
7 9
7 2
6 6
7 4
Sample Output 0
4
Explanation 0
You can finish the first 4 problems, which will take 3+7+7+6=23 seconds. Attempting the fifth problem will result in 23+7=30 seconds, which is greater than T=29.
Sample Input 1
6 5
6 6
7 10
9 4
9 11
10 10
10 0
Sample Output 1
This exam is impossible!
Explanation 1
None of the problems have t_i <= T=5, so it is impossible to finish even a single problem.
The actual code
def solve(n,t,problems): def main(): if __name__ == "__main__": |
Step by step
Solved in 4 steps with 3 images