이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
struct thing{
int core,clock,price,type;
};
bool cmp(thing q,thing w ){
if(q.clock!=w.clock){
return q.clock<w.clock;
}
else{
return q.type>w.type;
}
}
int main(){
int n;
cin>>n;
thing barang[n+1];
vector<thing>tmp;
int sum=0;
for(int q=1;q<=n;q++){
cin>>barang[q-1].core>>barang[q-1].clock>>barang[q-1].price;
barang[q-1].type=0;
tmp.push_back(barang[q-1]);
sum+=barang[q-1].price;
}
int m;
cin>>m;
for(int q=1;q<=m;q++){
cin>>barang[n+q-1].core>>barang[n+q-1].clock>>barang[n+q-1].price;
barang[n+q-1].type=1;
tmp.push_back(barang[n+q-1]);
}
sort(tmp.begin(),tmp.end(),cmp);
long long dp[sum+2];
for(int w=0;w<=sum;w++){
dp[w]=-1e15;
}
dp[0]=0;
for(int q=n+m;q>=1;q--){
auto [a,b,c,tipe]=tmp[q-1];
if(tipe==0){
for(int w=sum;w>=a;w--){
dp[w]=max(dp[w],dp[w-a]-c);
}
}
else{
for(int w=0;w+a<=sum;w++){
dp[w]=max(dp[w],dp[w+a]+c);
}
}
}
long long ans=0;
for(int q=0;q<=sum;q++){
ans=max(ans,dp[q]);
}
cout<<ans<<endl;
}
# | 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... |