이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct pro {
int cores;
int fan;
int price;
} comp[4001];
int main() {
int N; cin >> N;
int maxc = 0;
for (int i = 0; i < N; ++i) {
cin >> comp[i].cores >> comp[i].fan >> comp[i].price;
comp[i].price = -comp[i].price;
maxc += comp[i].cores;
}
int M; cin >> M;
for (int i = N; i < N + M; ++i) {
cin >> comp[i].cores >> comp[i].fan >> comp[i].price;
comp[i].cores = -comp[i].cores;
}
sort(comp, comp + N + M,[](const pro &A, const pro &B){
return (A.fan != B.fan) ? A.fan > B.fan : A.price < B.price;
});
vector<ll> pref(maxc + 1, INT64_MIN), now(maxc + 1, INT64_MIN);
pref[0] = 0; now[0] = 0;
for (int i = 0; i < N + M; ++i) {
for (int c = 0; c <= maxc; ++c) {
int pref_cores = c - comp[i].cores;
if (0 <= pref_cores && pref_cores <= maxc && pref[pref_cores] != INT64_MIN) {
now[c] = max(now[c], pref[pref_cores] + comp[i].price);
}
}
for (int c = 0; c <= maxc; ++c) pref[c] = now[c];
//cout << now[0] << '\n';
}
cout << *max_element(pref.begin(), pref.end());
}
# | 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... |