이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct computer{
ll f;
ll c;
ll v;
};
computer wej[4003];
ll dp[100003];
ll oo=1e18;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,m;
cin >> n;
for (ll i = 0; i<n; i++){
cin >> wej[i].c >> wej[i].f >> wej[i].v;
wej[i].v=-wej[i].v;
}
cin >> m;
for (ll i = n; i<n+m; i++){
cin >> wej[i].c >> wej[i].f >> wej[i].v;
wej[i].c=-wej[i].c;
}
sort(wej,wej+n+m,[](computer a, computer b){return (a.f==b.f?a.c>b.c:a.f>b.f);});
fill(dp,dp+100002,-oo);
dp[0]=0;
for (ll i = 0; i<n+m; i++){
if (wej[i].c>0){
for (ll j = 100000-wej[i].c; j>=0; j--){
dp[j+wej[i].c]=max(dp[j+wej[i].c],dp[j]+wej[i].v);
}
}
else{
for (ll j = -wej[i].c; j<=100000; j++){
dp[j+wej[i].c]=max(dp[j+wej[i].c],dp[j]+wej[i].v);
}
}
}
ll ans=0;
for (ll i = 0; i<=100000; i++)ans=max(ans,dp[i]);
cout << ans << '\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... |