Skip to content

Instantly share code, notes, and snippets.

@praveeng1618
Created September 29, 2019 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save praveeng1618/20193c41f8fa13d5fdffde4be1281390 to your computer and use it in GitHub Desktop.
Save praveeng1618/20193c41f8fa13d5fdffde4be1281390 to your computer and use it in GitHub Desktop.
maximum power
power=[]
klist=[]
def pokemon(q):
for j in range(q):
z, y = input().split()
y=int(y)
if z=='a':
power.append(y)
elif z=='i':
for s in range(len(power)):
power[s]=power[s]+y
elif z=='d':
for s in range(len(power)):
power[s]=power[s]-y
else:
klist.append(y)
power.sort()
power.reverse()
for s in klist:
print(power[s-1])
klist.clear()
power.clear()
t=int(input())
for i in range(t):
q=int(input())
pokemon(q)
@praveeng1618
Copy link
Author

Maximum power

Mike is a Pokemon trainer and always roams arcuri the Pokemon world. The pokemon world contains two major stops

Stop 1: Decrement in the power of all the pokemon, trainers have at that point of time by some X.

Stop 2: increment in the power of all the pokemon, trainers have at that point of time by some x

Help Mike determine the Kth largest power of the pokemon that he has with him

INPUT FORMAT :

First line. T denoting the number of test cases

Each test case contains Q queries

Each query is Of four types (A. I. D, P)
A:Add a new pokemon with the power X (A, X)
I :(Stop 2) (1, X)
D: (Stop 1) (D, X)
P: Print the power of the Kth largest pokemon (P, K)

Output format
Print the answer for all type P queries in a new line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment