이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pii pair<ll,ll>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define freeopen freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define mod 1000000000
#define pb push_back
#define mk make_pair
#define ll long long
#define foor(x,vec) for(auto x:vec ){cout<<x<<" ";}
#define fi first
#define se second
#define MAXN 500069
#define lld long double
#define cha ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ffl fflush(stdout)
#define sst string
#define pii pair<ll,ll>
ll mvx[]={0,0,-1,1};
ll mvy[]={1,-1,0,0};
ll n,m,c[2009],C[2009],F[2009],f[2009],v[2009],V[2009];
ll dp[200069];
void solve(){
cin>>n;
vector <pair<pii,pii>> vec;
REP(i,1,n){
cin>>c[i]>>f[i]>>v[i];
vec.pb({{f[i],1},{c[i],v[i]}});
}
cin>>m;
REP(i,1,m){
cin>>C[i]>>F[i]>>V[i];
vec.pb({{F[i],0},{C[i],V[i]}});
}
REP(i,1,100000)dp[i]=-1e18;
sort(vec.begin(),vec.end(),greater<pair<pii,pii>>());
ll ans=0;
for(auto x : vec){
if(x.fi.se){
for(ll i=100000;i>=x.se.fi;i--)
dp[i]=max(dp[i],dp[i-x.se.fi]-x.se.se);
}
else{
for(ll i=0;i<=100000;i++){
if(i+x.se.fi<=100000)
dp[i]=max(dp[i],dp[i+x.se.fi]+x.se.se);
else break;
}
}
REP(i,0,10000)ans=max(ans,dp[i]);
}
cout<<ans<<endl;
}
int main(){
ll tc;
tc=1;
// cin>>tc;
while(tc--){
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... |