Submission #544649

#TimeUsernameProblemLanguageResultExecution timeMemory
544649pokmui9909막대기 (KOI13_game)C++17
100 / 100
60 ms7028 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...