Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement