Codeforces #304 Div2 E. Soldier and Traveling

2250ptということでいつもより易しめ。 http://codeforces.com/contest/546/problem/E