// 想定TLE解法 #include using namespace std; using ll = long long; int main() { ll n,k; cin >> n >> k; vector a(k+1); for (size_t i=0; i> a[i]; a[k] = a[0] + 2*n; vector an = a; for (size_t i=0; i<=k; i++) an[i] -= a[0]; ll ans = 0; for (ll s = an[0]+1; s < an[1]; s++) { ll ok = 0, ng = n; auto is_ok = [&] (ll mid) -> bool { ll x = 2 * mid; ll t = s; for (size_t i=0; i= an[i+2]) return false; t = max(t+x, an[i+1]+1); } return t+x <= s+2*n; }; while (ng - ok > 1) { ll mid = (ok + ng) / 2; if (is_ok(mid)) ok = mid; else ng = mid; } ans = max(ans, 2*ok); } cout << ans << endl; }