fork download
  1. def f(c,l):
  2. def r(t):p=abs(t[0]-x);q=abs(t[1]-y);return p+q-.5*min(p,q)
  3. v=0;x,y=0,0
  4. while c>0 and len(l)>0:
  5. l.sort(key=r);c-=r(l[0]);x,y=l.pop(0)
  6. if c>=0:v+=1
  7. return v
  8.  
  9. print f(4,[(-1,0), (1,0), (2,0), (3,0), (4,0), (5,0)])
  10. print f(4,[(1,1), (2,2), (3,3)])
  11. print f(5,[(1,1), (2,1), (3,1), (4,1), (5,0), (5,1)])
  12.  
  13. print f(2016,[(1,1), (2,2), (3,3)])
Success #stdin #stdout 0s 9024KB
stdin
Standard input is empty
stdout
3
2
4
3