이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int nx=2e3+5, cx=51;
int n, m, c, f, p;
long long dp[2][nx*cx], ans=0;
struct com
{
bool type;
int c, f, v;
com(bool type, int c, int f, int v): type(type), c(c), f(f), v(v){}
bool operator< (const com &o)
{
if (f==o.f) return type<o.type;
return f<o.f;
}
};
vector<com> v;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=0; i<n; i++) cin>>c>>f>>p, v.push_back(com(1, c, f, p));
cin>>m;
for (int i=0; i<m; i++) cin>>c>>f>>p, v.push_back(com(0, c, f, p));
sort(v.begin(), v.end());
for (int i=0; i<nx*cx; i++) dp[0][i]=dp[1][i]=-1e18;
for (int i=n+m-1; i>=0; i--)
{
int cur=i%2, pv=1-cur;
if (i==n+m-1) dp[pv][0]=0;
com cr=v[i];
for (int j=0; j<nx*cx; j++) dp[cur][j]=dp[pv][j];
if (cr.type==1) for (int j=cr.c; j<nx*cx; j++) dp[cur][j]=max(dp[cur][j], dp[pv][j-cr.c]-cr.v);
else for (int j=0; j+cr.c<nx*cx; j++) dp[cur][j]=max(dp[cur][j], dp[pv][j+cr.c]+cr.v);
}
for (int i=0; i<nx*cx; i++) ans=max(ans, dp[0][i]);
cout<<ans;
}
# | 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... |