이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int maxn = 2000;
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<vector<int> > dp;
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());
dp.assign(1 + n, vector<int> (1 + m, -inf));
dp[0][0] = 0;
for(int i = 1; i <= n; i++) {
dp[i][0] = 0;
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
if(computers[i].freq >= orders[j].freq) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + orders[j].val - computers[i].val);
}
}
}
cout << dp[n][m] << "\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... |