This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
pair<ll, ll> A[100005];
ll D[1000005][2];
vector<ll> X, Y;
ll N, L;
int main()
{
cin.tie(0); cout.tie(0);
ios_base::sync_with_stdio(false);
cin >> N >> L;
for(int i = 1; i <= N; i++)
{
cin >> A[i].first >> A[i].second;
X.push_back(A[i].first);
Y.push_back(A[i].second);
}
X.push_back(N); Y.push_back(N);
sort(A + 1, A + N + 1);
sort(X.begin(), X.end());
sort(Y.begin(), Y.end());
X.erase(unique(X.begin(), X.end()), X.end());
Y.erase(unique(Y.begin(), Y.end()), Y.end());
ll ans = 0;
for(int i = 1; i <= N; i ++)
{
ll x = lower_bound(X.begin(), X.end(), A[i].first) - X.begin();
ll y = lower_bound(Y.begin(), Y.end(), A[i].second) - Y.begin();
ll k = abs(X[x] - Y[y]) + L;
ll a = D[x][0], b = D[y][1];
D[x][0] = max(D[x][0], b + k);
D[y][1] = max(D[y][1], a + k);
ans = max({ans, D[x][0], D[y][1]});
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |