Advertisement
SVXX

DeleteFriends

Jul 27th, 2014
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. class TestCase:
  4.     def __init__(self, N, delK, list_friends):
  5.         if N < 1 or N > 100000:
  6.             raise ValueError('no, {0}'.format(N))
  7.         if K < 0 or K > N:
  8.             raise ValueError('no, {0}'.format(K))
  9.         for pop in list_friends:
  10.             if pop < 0 or pop > 100:
  11.                 raise ValueError('no, {0}'.format(pop))
  12.         self.N = N
  13.         self.delK = delK
  14.         self.list_friends = list_friends
  15.    
  16.     def algorithm(self):
  17.         delFriend = False
  18.         for i in range(0, len(self.list_friends)):
  19.             if(self.list_friends[i] < self.list_friends[i+1]):
  20.                 del self.list_friends[i]
  21.                 delFriend = True
  22.                 break
  23.         if delFriend == False:
  24.             del self.list_friends[len(self.list_friends)-1]
  25.         return self.list_friends
  26.        
  27. cases = long(raw_input())
  28. for x in range(0, cases):
  29.     vitals = raw_input()
  30.     vitals = vitals.split()
  31.     N, K = long(vitals[0]), long(vitals[1])
  32.     pops = raw_input().split()
  33.     pops = [long(pop) for pop in pops]
  34.     tc = TestCase(N, K, pops)
  35.     output = None
  36.     for x in range(0, K):
  37.         output = tc.algorithm()
  38.     output_str = ""
  39.     for x in output:
  40.         output_str = output_str + str(x) + " "
  41.     print(output_str)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement