Created
September 20, 2016 11:05
-
-
Save yurahuna/17a763d0250b164d1eeb149b692fc1f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
signed main() { | |
std::ios::sync_with_stdio(false); | |
std::cin.tie(0); | |
int T, N; | |
cin >> T >> N; | |
vi s(N), t(N); | |
rep(i, N) cin >> s[i] >> t[i]; | |
// スタート位置についてしゃくとり | |
int ans = 0; | |
int r = 0; | |
int len = 0; | |
rep(l, N) { | |
while (r < N && t[r] <= s[l] + T) { | |
len += t[r] - s[r]; | |
r++; | |
} | |
int vim = 0; | |
if (r < N) vim += max(0ll, (s[l] + T) - s[r]); | |
ans = max(ans, len + vim); | |
len -= t[l] - s[l]; | |
} | |
cout << ans << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment