This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
#define REP(i, n) for(int i = 0;i < n;i ++)
#define REP1(i, n) for(int i = 1;i <= n;i ++)
#define FILL(i, n) memset(i, n, sizeof(i))
#define X first
#define Y second
#define pb push_back
#define SZ(_a) ((int)(_a).size())
#define ALL(_a) (_a).begin(), (_a).end()
#ifdef brian
#define IOS()
template<typename T>void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...t> void _do(T &&x, t &&...X){cerr<<x<<", ";_do(X...);}
#define debug(...) {\
fprintf(stderr, "%s - %d (%s) = ", __PRETTY_FUNCTION__, __LINE__, #__VA_ARGS__);\
_do(__VA_ARGS__);\
}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(...)
#define endl '\n'
#endif
const ll MAXn = 2e3 + 5;
const ll INF = ll(1e17);
const ll MOD = 1000000007;
struct tg{
ll c, f, v, tp;
};
vector<tg> dt;
ll dp[2][51 * MAXn];
int main(){
IOS();
ll n, m;
cin>>n;
REP(i, n)
{
ll c, f, v;
cin>>c>>f>>v;
dt.pb({c, f, v, 1});
}
cin>>m;
REP(i, m)
{
ll c, f, v;
cin>>c>>f>>v;
dt.pb({c, f, v, 0});
}
sort(ALL(dt), [](tg &a, tg &b){return ii(a.f, a.tp) < ii(b.f, b.tp);});
ll C = 0;
ll fg = 0;
for(auto &t:dt)
{
fg = !fg;
for(int i = 0;i <= C;i ++)dp[fg][i] = dp[!fg][i];
if(t.tp == 0)
{
for(int i = 0;i <= C;i ++)dp[fg][i + t.c] = max(dp[fg][i + t.c], dp[!fg][i] + t.v);
C += t.c;
}
else
{
for(int i = 0;i <= C;i ++)dp[fg][max(0LL, i - t.c)] = max(dp[fg][max(0LL, i - t.c)], dp[fg][i] - t.v);
}
}
cout<<dp[fg][0]<<endl;
}
# | 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... |