#include <bits/stdc++.h>
#define el '\n'
#define FNAME "NAME"
#define allof(x) x.begin(),x.end()
#define allof1(x) x.begin()+1,x.end()
#define mset(x,n) memset(x,(n),sizeof(x))
using namespace std;
const long long MOD = (long long) 1e9 + 7;
template<class X,class Y> bool minimize(X &a,Y b){ if (a>b) {a=b; return true;} return false;}
template<class X,class Y> bool maximize(X &a,Y b){ if (a<b) {a=b; return true;} return false;}
void setup(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
if (fopen(FNAME".inp","r")){
freopen(FNAME".inp","r",stdin);
freopen(FNAME".out","w",stdout);
}
}
const long long INF = (long long) 1e16 + 15092007;
struct PC{
int core;
long long req,price;
PC():core(0),req(0),price(0) {}
PC(int C,long long f,long long P):core(C),req(f),price(P) {}
bool operator < (const PC &other) const{
return req > other.req;
}
};
int n,m;
vector<PC> a;
vector<PC> order;
int totalC;
void init(){
cin>>n;
a.resize(n);
for (PC &x : a) cin>>x.core>>x.req>>x.price,totalC+=x.core;
cin>>m;
order.resize(m);
for (PC &x : order) cin>>x.core>>x.req>>x.price,totalC+=x.core;
}
void sol(){
sort(allof(a));
sort(allof(order));
int ptr = 0;
vector<long long> dp(totalC+1,-INF);
dp[0] = 0;
int curC = 0;
for (const PC &x : order){
while (ptr < n and a[ptr].req >= x.req){
int c = a[ptr].core;
long long price = a[ptr].price;
for (int k = curC; k>=0 ; k--){
if (dp[k]==-INF) continue;
maximize(dp[k + c], dp[k] - price);
}
ptr++;
curC+=c;
}
int need = x.core;
long long pay = x.price;
if (need <= curC){
vector<long long> nxt = dp;
for (int k = need; k <= curC; k++){
if (dp[k] == -INF) continue;
maximize(nxt[k - need],dp[k] + pay);
}
dp.swap(nxt);
}
}
cout<<*max_element(allof(dp));
}
int main(){
setup();
init();
sol();
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'void setup()':
clo.cpp:16:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | freopen(FNAME".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:17:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | freopen(FNAME".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |