이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define MAXN 100001
typedef long long ll;
struct Stick {
ll t, d;
};
int N;
ll L;
Stick A[MAXN];
ll solve(int p) {
ll 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].d==A[p].d && A[pp].t>A[p].t))
ret = max(ret, solve(pp));
}
return ret+L+abs(A[p].t-A[p].d);
}
int main() {
scanf("%d%lld", &N, &L);
for (int i=1; i<=N; ++i) scanf("%lld%lld", &A[i].t, &A[i].d);
ll sol = 0;
for (int i=1; i<=N; ++i)
sol = max(sol, solve(i));
printf("%lld", 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... |