Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. n, d = map(int, raw_input().split())
  2.  
  3. tsts = []
  4. for i in xrange(n):
  5.     money, friendship = map(int, raw_input().split())
  6.     for i in xrange(len(tsts)):
  7.         t = tsts[i]
  8.         maxi = t['mmax']
  9.         mini = t['mmin']
  10.         if(money < maxi) and (money > mini):
  11.             n = {'mmax' : money + d  if (money + d) < maxi else maxi, 'mmin': money - d if (money - d) > mini else mini, 'f': t['f'] + friendship}      
  12.             tsts.append(n)
  13.     tsts.append({'mmax':money + d, 'mmin': money - d, 'f': friendship})
  14.  
  15. print(max(tsts, key=lambda t: t['f'])['f'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement