이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int maxn = 2000;
const int maxc = 50;
const int inf = 1e16 + 42;
struct computer {
int cores, freq, val;
bool operator < (const computer & other) const {
return freq < other.freq;
}
};
int n, m;
vector<computer> computers, orders;
vector<int> dpmin, dpmax;
void solve() {
cin >> n;
computers.resize(1 + n);
for(int i = 1; i <= n; i++) {
cin >> computers[i].cores >> computers[i].freq >> computers[i].val;
}
sort(computers.begin() + 1, computers.end());
cin >> m;
orders.resize(1 + m);
for(int i = 1; i <= m; i++) {
cin >> orders[i].cores >> orders[i].freq >> orders[i].val;
}
sort(orders.begin() + 1, orders.end());
dpmin.assign(1 + maxn * maxc, inf);
dpmin[0] = 0;
for(int i = 1; i <= n; i++) {
for(int j = maxn * maxc; j >= computers[i].cores; j--) {
dpmin[j] = min(dpmin[j], dpmin[j - computers[i].cores] + computers[i].val);
}
}
for(int j = maxn * maxc - 1; j >= 0; j--) {
dpmin[j] = min(dpmin[j], dpmin[j + 1]);
}
dpmax.assign(1 + maxn * maxc, -inf);
dpmax[0] = 0;
for(int i = 1; i <= m; i++) {
for(int j = maxn * maxc; j >= orders[i].cores; j--) {
dpmax[j] = max(dpmax[j], dpmax[j - orders[i].cores] + orders[i].val);
}
}
int ans = 0;
for(int i = 1; i <= maxn * maxc; i++) {
ans = max(ans, dpmax[i] - dpmin[i]);
}
cout << ans << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |