daily pastebin goal
84%
SHARE
TWEET

Untitled

a guest Aug 13th, 2017 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import sys
  5.  
  6. a = sys.stdin.readline().strip()
  7. leng, _ = map(int, a.split())
  8.  
  9. a = sys.stdin.readline().strip()
  10. opors = map(int, a.split())
  11.  
  12. if len(opors) < 4:
  13.     print leng
  14. else:
  15.     res = opors[1] + leng - opors[-2]
  16.     for i in xrange(1, len(opors) - 2):
  17.         right = hi = opors[i + 1]
  18.         left = lo = opors[i]
  19.         if left < (right - left):
  20.             hi = left * 2
  21.         if leng - right < (right - left):
  22.             lo = 2*right - leng
  23.  
  24.         if hi < lo:
  25.             res += right - left
  26.         else:
  27.             res += (right - hi)
  28.             res += (lo - left)
  29.  
  30.     print res
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top