#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[A][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";
}
Compilation message
/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax
collect2: error: ld returned 1 exit status