이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Dost SEFEROĞLU
#pragma GCC optimize("O3,unroll-loops,Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define vi vector<int>
const int N = 2e7+1,inf = 2e18,MOD = 1e9+7;
struct Order{
int core,power,price;
};
void solve() {
int n;
cin >> n;
vector<Order> orders;
for (int i=1;i<=n;i++) {
int c,f,p;
cin >> c >> f >> p;
orders.push_back({c,f,-p});
}
int m;
cin >> m;
for (int i=1;i<=m;i++) {
int c,f,p;
cin >> c >> f >> p;
orders.push_back({-c,f,p});
}
sort(orders.begin(),orders.end(),[&](Order o1,Order o2) {
if (o1.power > o2.power) return true;
if (o1.power < o2.power) return false;
return o1.core > o2.core;
});
n = n+m;
int dp[200001],dp2[200001];
for (int i=0;i<=200000;i++) dp[i] = dp2[i] = -inf;
dp2[0] = 0;
for (int i=0;i<n;i++) {
for (int j=0;j<=200000;j++) dp[j] = -inf;
for (int c = 0;c<=200000;c++) {
if (dp2[c] == -inf) continue;
dp[c] = max(dp[c],dp2[c]);
if (c+orders[i].core >= 0 && c+orders[i].core <= 200000) {
dp[c+orders[i].core] = max(dp[c+orders[i].core],dp2[c]+orders[i].price);
}
}
for (int j=0;j<=200000;j++) dp2[j] = dp[j];
}
cout << max(0ll,*max_element(dp2,dp2+200001)) << '\n';
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
# | 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... |