이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define MS(x,y) memset((x),(y),sizeof((x)))
using namespace std;
const ll MN = 1000000007;
vector<pair<pair<ll,ll>, pair<ll,ll>>> a(4005);
int main()
{
#if LOCAL_DEBUG
fstream cin("in.txt");
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n,m;
cin>>n;
ll ctr = 0;
for (ll i = 0; i<n; i++) {
ll c,f,v;
cin>>c>>f>>v;
a[i] = { {-f,0} , {c,-v} };
ctr += c;
}
cin>>m;
for (ll i = 0; i<m; i++) {
ll c,f,v;
cin>>c>>f>>v;
a[i+n] = { {-f,1} , {-c,v} };
}
a.resize(n+m);
sort(a.begin(),a.end());
const ll sajz = ctr+100;
vector<ll> dp(sajz);
for (ll i = 0; i<sajz; i++) dp[i] = -(MN*MN);
dp[0] = 0;
vector<ll> tempDp(sajz);
for (ll i = 0; i<n+m; i++) {
ll c = a[i].second.first, v = a[i].second.second;
tempDp = dp;
for (ll j = max(0ll,c); j<=ctr; j++) tempDp[j] = max(tempDp[j], dp[j-c]+v);
swap(tempDp,dp);
}
ll res = 0;
for (ll i = 0; i<sajz; i++) res = max(res,dp[i]);
cout<<res<<endl;
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... |