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 <cstdio>
#include <algorithm>
using namespace std;
#define MAXN 100001
struct Stick {
int t, d;
};
int N, L;
Stick A[MAXN];
int solve(int p) {
int ret = 0;
for (int pp=1; pp<=N; ++pp) if (p != pp) {
if ((A[pp].t==A[p].t || A[pp].d==A[p].d) && (A[pp].t>=A[p].t && A[pp].d>=A[p].d))
ret = max(ret, solve(pp));
}
return ret+L+abs(A[p].t-A[p].d);
}
int main() {
scanf("%d%d", &N, &L);
for (int i=1; i<=N; ++i) scanf("%d%d", &A[i].t, &A[i].d);
int sol = 0;
for (int i=1; i<=N; ++i)
sol = max(sol, solve(i));
printf("%d", sol);
}
# | 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... |