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;
#define int long long
const int N = 3e3+3, A = 3e4+4, inf = LLONG_MAX;
int n, a[N], b[N], x[A], y[A], dp[2][A];
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
int l1 = 0;
int l2 = 0;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
for (int j = 0; j < b[i]-a[i]; j++) {
x[l1++] = i;
}
for (int j = 0; j < a[i]-b[i]; j++) {
y[l2++] = i;
}
}
for (int i = 0; i < l1; i++) {
for (int j = i; j < l2; j++) {
dp[i][j] = min(abs(x[i] - y[j]) + (i ? dp[(i-1)][j-1] : 0), (j > i ? dp[i][j-1] : inf));
}
}
cout << dp[(l1-1)][l2-1] << "\n";
}
# | 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... |