이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll N = 100003, mod = 1e9 + 7, inf = 1e18 + 7;
struct node
{
int core, rate;
ll cost;
}t;
bool cnt(node a, node b){
if(a.rate == b.rate) return a.cost < b.cost;
return a.rate > b.rate;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n;
vector<node> v;
for(int i = 0; i < n; ++i){
cin >> t.core >> t.rate >> t.cost;
t.cost = -t.cost;
v.push_back(t);
}
cin >> m;
for(int i = 0; i < m; ++i){
cin >> t.core >> t.rate >> t.cost;
t.core = -t.core;
v.push_back(t);
}
sort(v.begin(), v.end(), cnt);
// for(int i = 0; i < v.size(); ++i) cout << v[i].cost << "\n";
vector<ll> last, dp(N, -inf);
dp[0] = 0;
for(auto i : v){
last = dp;
for(int c = 0; c < N; ++c){
if(0 <= c - i.core && c - i.core < N && last[c - i.core] != -inf){
dp[c] = max(dp[c], last[c - i.core] + i.cost);
}
}
}
ll ans = 0;
for(int i = 0; i < N; ++i){
ans = max(ans, dp[i]);
}
cout << ans;
}
# | 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... |