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;
typedef long long int lld;
typedef pair<int, int> pii;
int N, L;
vector<pii> S;
lld D[100005];
lld solve(int p) {
if(D[p] != -1) return D[p];
lld ret = 0;
for(int i = 0; i < p; i++) {
if(S[i].second == S[p].second)
ret = max(ret, solve(i));
if(S[i].first == S[p].first && S[i].second < S[p].second)
ret = max(ret, solve(i));
}
return D[p] = ret + abs(S[p].first - S[p].second) + L;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
memset(D, -1, sizeof(D));
cin >> N >> L;
for(int i = 0; i < N; i++) {
int x, y;
cin >> x >> y;
S.push_back(pii(x, y));
}
sort(S.begin(), S.end());
lld rst = 0;
for(int i = 0; i < N; i++) rst = max(rst, solve(i));
cout << rst;
return 0;
}
# | 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... |