이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 100;
int n, m;
long long dp[60300];
long long d[60300];
int A, B;
int a[maxn], b[maxn];
int main() {
cin >> n;
for(int i=1; i<=n; i++) {
cin >> a[i] >> b[i];
A += a[i];
B += b[i];
}
if(A <= 30000) {
for(int j = 0; j <= 2*A; j++) {
dp[j] = 1e18;
}
dp[A] = 0;
for(int i = 1; i <= n; i++) {
for(int j = 0; j <= 2 * A; j++) {
d[j] = dp[j] + abs(j-A);
dp[j] = 1e18;
}
for(int j = 0; j <= 2 * A; j++) {
int k = j + a[i] - b[i];
if(k >= 0 && k <= 2 * A) {
dp[k] = min(dp[k], d[j]);
}
}
for(int j = 2 * A-1; j >= 0; j--) {
dp[j] = min(dp[j+1], dp[j]);
}
}
cout << dp[A];
}
}
# | 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... |