SHARE
TWEET

Untitled

a guest Nov 10th, 2013 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2. http://main.edu.pl/pl/archive/oig/6/prz
  3. """
  4. import sys
  5.  
  6.  
  7. def press_buttons(button_count, presses):
  8.     """button_count is number of buttons EXCLUDING the special one.
  9.    In presses, buttons are meant to be indexed from 0.
  10.    """
  11.     states = [0] * button_count
  12.     max_state = min_state = 0
  13.  
  14.     for press in presses:
  15.         if press == button_count:
  16.             min_state = max_state
  17.         else:
  18.             states[press] += 1
  19.             max_state = max(max_state, states[press])
  20.  
  21.     for i in xrange(button_count):
  22.         states[i] = max(min_state, states[i])
  23.     return states
  24.  
  25.  
  26. def read_input():
  27.     button_count, presses_count = map(int, sys.stdin.readline().split())
  28.     presses = [press - 1  # index buttons from 0
  29.                for press in map(int, sys.stdin.readline().split())]
  30.     return button_count, presses
  31.  
  32.  
  33. if __name__ == '__main__':
  34.     button_count, presses = read_input()
  35.     print ' '.join(map(str, press_buttons(button_count, presses)))
RAW Paste Data
Top