이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
struct Object{
int c, f, v;
bool operator< (const Object& o) const{
return (f == o.f && v < o.v) || (f > o.f);
}
};
int main(){
int n;
cin >> n;
vector<Object> objects;
for(int i = 0; i < n; i++){
int c, f, v;
cin >> c >> f >> v;
objects.push_back({c, f, -v});
}
int m;
cin >> m;
for(int i = 0; i < m; i++){
int c, f, v;
cin >> c >> f >> v;
objects.push_back({-c, f, v});
}
sort(objects.begin(), objects.end());
vector<long long> dp(100001, -1e14);
dp[0] = 0;
for(int i = 0; i < n + m; i++){
vector<long long> ndp(100001, -1e14);
ndp[0] = 0;
for(int c = 0; c <= 100000; c++){
if(c - objects[i].c <= 100000 && objects[i].c <= c){
ndp[c] = max(ndp[c], dp[c - objects[i].c] + objects[i].v);
}
}
for(int c = 0; c <= 100000; c++){
dp[c] = max(dp[c], ndp[c]);
}
}
long long maxVal = -1e14;
for(int i = 0; i <= 100000; i++){
maxVal = max(maxVal, dp[i]);
}
cout << maxVal << "\n";
}
# | 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... |