이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pld pair<ld, ld>
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << #x << " => " << x << endl
#define all(x) x.begin(),x.end()
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int n;cin>>n;
ll c[n],f[n],v[n];
for(int i=0;i<n;i++) cin>>c[i]>>f[i]>>v[i];
int m;cin>>m;
ll C[m],F[m],V[m];
for(int i=0;i<m;i++) cin>>C[i]>>F[i]>>V[i];
vector<pii> a;
for(int i=0;i<n;i++) a.pb({f[i],i});
for(int i=0;i<m;i++) a.pb({F[i],n+i});
sort(all(a),greater<pii>());
ll dp[2][n*50+10];
for(int j=1;j<=n*50;j++) dp[1][j]=-1e15;
dp[1][0]=0;
for(int i=0;i<n+m;i++)
{
ll idx=a[i].se;
for(int j=0;j<=n*50;j++)
{
dp[i%2][j]=dp[(i+1)%2][j];
if(idx<n && j-c[idx]>=0) dp[i%2][j]=max(dp[i%2][j],dp[(i+1)%2][j-c[idx]]-v[idx]);
else if(idx>=n && j+C[idx-n]<=n*50) dp[i%2][j]=max(dp[i%2][j],dp[(i+1)%2][j+C[idx-n]]+V[idx-n]);
}
}
ll ans=0;
for(int j=0;j<=n*50;j++) ans=max(ans,dp[(n+m+1)%2][j]);
cout<<ans;
return 0;
}
# | 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... |