#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e3, A = 3e4, 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%2][j] = min(abs(x[i] - y[j]) + (i ? dp[(i-1)%2][j-1] : 0), (j > i ? dp[i%2][j-1] : inf));
}
}
cout << dp[(l1-1)%2][l2-1] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |