이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = array<int, 2>;
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
template<class T> bool smax(T &a, T b) {
return a < b ? a = b, 1 : 0;
}
template<class T> bool smin(T &a, T b) {
return a > b ? a = b, 1 : 0;
}
int main() {
cin.tie(0) -> sync_with_stdio(0);
int n; cin >> n;
vector<array<int, 3>> ord;
// {cores_added, freq, val_added}
int tot = 0;
for (int i = 0; i < n; i++) {
int c, f, v;
cin >> c >> f >> v;
ord.push_back({c, f, -v});
tot += c;
}
int m; cin >> m;
for (int i = 0; i < m; i++) {
int c, f, v;
cin >> c >> f >> v;
ord.push_back({-c, f, v});
}
sort(all(ord), [&](auto &i, auto &j) -> bool {
return (i[1] == j[1]) ? i[2] < j[2] : i[1] > j[1];
});
const ll INF = 1e15;
vector<ll> dp(tot + 1, -INF);
dp[0] = 0;
for (auto [c, f, v] : ord) {
vector<ll> dp_t(tot + 1, -INF);
for (int i = 0; i <= tot; i++) {
int nxt = i + c;
if (nxt >= 0 && nxt <= tot && dp[i] != -INF) {
smax(dp_t[nxt], dp[i] + v);
}
smax(dp_t[i], dp[i]);
}
dp = move(dp_t);
}
cout << *max_element(all(dp)) << "\n";
}
/**
* Cloud Computing - CEOI 2018
* The only constraint on the actual cores we
* can give to certain orders are the frequencies
* of the cores. Thus, we can sort both the orders
* and the computers in order.
*
* Then, because the sum of the cores is low, we knapsack
* on the number of cores. Our DP state is the following:
* dp[cores_used][cur_item] = most profit possible.
*/
# | 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... |