Question: Hi I am trying to solve this problem on kattis and the code works it is just exceeding the time limit. here is the code

Hi I am trying to solve this problem on kattis and the code works it is just exceeding the time limit.

Hi I am trying to solve this problem on kattis and thecode works it is just exceeding the time limit. here is thecode that needs to be modified. n,t=map(int,input().split()) a=list(map(int,input().split())) if t==1: c=0 fori in range(n): for j in range(i,n): if a[i]!=a[j] and a[i]+a[j]==7777: c=1print("Yes") break if c==0: print("No") elif t==2: k=len(list(set(a))) if n==k: print("Unique") else:here is the code that needs to be modified.

n,t=map(int,input().split()) a=list(map(int,input().split())) if t==1: c=0 for i in range(n): for j in range(i,n): if a[i]!=a[j] and a[i]+a[j]==7777: c=1 print("Yes") break if c==0: print("No") elif t==2: k=len(list(set(a))) if n==k: print("Unique") else: print("Contains duplicate") elif t==3: d={} for i in a: if i not in d.keys(): d[i]=1 else: d[i]+=1 c=0 p=[] for k,v in d.items(): if v>(n//2): p.append(k) print(*p) elif t==4: a.sort() if n%2==0: print(a[n//2-1],a[n//2]) else: print(a[n//2]) elif t==5: p=[] for i in a: if i>99 and i

- Sample Accepted (0/100) - Secret Time Limit Exceeded (70/100) 00000 You are given two integers N and t; and then an array A of N integers ( 0 -based indexing). Based on the value of t, you will perform an action on A. \begin{tabular}{l|l} \hlinet & Action Needed \\ \hline 1 & Print "Yes" if there are two integers xA and yA such that x=y and x+y=7777, or "No" otherwise (without the quotes) \\ 2 & Print "Unique" if all integers in A are different; \\ or print "Contains duplicate" otherwise (without the quotes) \\ 3 & Find and print the integer that appears >2N times in A; \\ or print 1 if such integer cannot be found \\ Find and print the median integer of A if N is odd; \\ or print both median integers of A if N is even (separate them with a single \\ space) \end{tabular} 5 Print integers in A that fall between a range [100999] in sorted order; (print a single space between two integers) Input The first line of the input contains an integer N and t ( 3N200000; 1t5) The second line of the input contains N non-negative 32 -bit signed integers. Output For each test case, output the required answer based on the value of t. Scoring There are 20 hidden test cases that test various requirements of this problem. All 20 test cases will be tested. Each hidden test case worth 5 points (the 5 sample test cases below worth 0 point). Sample Input 1 Sample Output 1 Sample Input 2 Sample Output 2 Sample Input 3 Sample Output 3 Sample Input 4 Sample Output 4 Sample Input 5 Sample Output 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!