Skip to content

Instantly share code, notes, and snippets.

@yurahuna
Created September 20, 2016 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yurahuna/17a763d0250b164d1eeb149b692fc1f5 to your computer and use it in GitHub Desktop.
Save yurahuna/17a763d0250b164d1eeb149b692fc1f5 to your computer and use it in GitHub Desktop.
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