# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
714361 | pashka | Potatoes and fertilizers (LMIO19_bulves) | C++14 | 1087 ms | 852 KiB |
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>
#define long long long int
#define DEBUG
using namespace std;
// @author: pashka
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
int M = 30001;
vector<int> d(2 * M, INT_MAX);
d[M] = 0;
for (int i = 0; i < n; i++) {
vector<int> dd(2 * M, INT_MAX);
for (int j = 0; j < 2 * M; j++) {
if (d[j] == INT_MAX) continue;
// cout << i << " " << j << " " << d[j] << "\n";
int x = a[i] - b[i];
if ((j - M) < 0) {
int y = x + (j - M);
dd[y + M] = min(dd[y + M], d[j] + abs(j - M));
} else {
for (int k = 0; k <= (j - M); k++) {
int y = x + k;
dd[y + M] = min(dd[y + M], d[j] + k);
}
}
}
d = dd;
}
int res = INT_MAX;
for (int i = M; i < d.size(); i++) {
res = min(res, d[i]);
}
cout << res << "\n";
return 0;
}
Compilation message (stderr)
# | 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... |