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>
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 real;
bool operator < (const computer & other) const {
if(freq == other.freq) {
return real > other.real;
}
return freq > other.freq;
}
};
int n, m;
vector<computer> all;
vector<int> dp;
void solve() {
cin >> n;
for(int i = 1; i <= n; i++) {
computer cur;
cin >> cur.cores >> cur.freq >> cur.val;
cur.real = true;
all.pb(cur);
}
cin >> m;
for(int i = 1; i <= m; i++) {
computer cur;
cin >> cur.cores >> cur.freq >> cur.val;
cur.real = false;
all.pb(cur);
}
sort(all.begin(), all.end());
dp.assign(1 + maxn * maxc, -inf);
dp[0] = 0;
for(computer cur : all) {
if(cur.real) {
for(int i = maxn * maxc; i >= cur.cores; i--) {
dp[i] = max(dp[i], dp[i - cur.cores] - cur.val);
}
} else {
for(int i = 0; i <= maxn * maxc - cur.cores; i++) {
dp[i] = max(dp[i], dp[i + cur.cores] + cur.val);
}
}
}
int ans = 0;
for(int i = 0; i <= maxn * maxc; i++) {
ans = max(ans, dp[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... |