Skip to content

Instantly share code, notes, and snippets.

@crazydiver
Created September 23, 2019 11:10
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 crazydiver/b54c1ae0f8ec2db39ca5391aa9b3ff70 to your computer and use it in GitHub Desktop.
Save crazydiver/b54c1ae0f8ec2db39ca5391aa9b3ff70 to your computer and use it in GitHub Desktop.
n, m = map(int, input().split())
mas = []
sumin = 0
sumout = 0
massorted = []
for i in range(n+m):
f = input()
ch = int(f[1:])
if f[0] == '-':
mas.append(ch)
massorted.append(ch)
sumout += ch
else:
massorted.sort(reverse=True)
i = 0
while sumin < sumout:
sumout -= massorted[i]
mas[mas.index(massorted[i])] = -1
massorted[i] = -1
i += 1
for j in range(len(mas)):
if mas[j] == -1:
print('declined')
else:
print('approved')
massorted = []
mas = []
sumin -= sumout
sumout = 0
print('resupplied')
sumin += ch
massorted.sort(reverse=True)
i = 0
while sumin<sumout:
sumout -= massorted[i]
mas[mas.index(massorted[i])] = -1
massorted[i] = -1
i += 1
for j in range(len(mas)):
if mas[j] == -1:
print('declined')
else:
print('approved')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment