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;
class state
{
public:
int c, f, v;
bool type;
state()
{
c = f = v = 0;
type = 0;
}
state(int _c, int _f, int _v, bool _type)
{
c = _c;
f = _f;
v = _v;
type = _type;
}
bool operator < (const state &v) const
{
if(f == v.f) return type < v.type;
return f < v.f;
}
bool operator == (const state &v) const
{
return f == v.f;
}
bool operator > (const state &v) const
{
if(f == v.f) return type > v.type;
return f > v.f;
}
};
int n, m;
state a[4005];
long long dp[2][4005 * 50];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
int ci, fi, vi;
for(int i = 1; i <= n; i++)
{
cin >> ci >> fi >> vi;
a[i] = {ci, fi, vi, 1};
}
cin >> fi;
ci = n;
n += fi;
for(int i = ci + 1; i <= n; i++)
{
cin >> ci >> fi >> vi;
a[i] = {ci, fi, vi, 0};
}
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
{
// cout << a[i].c << " " << a[i].f << " " << a[i].v << " " << a[i].type << "\n";
}
memset(dp, -0x3f, sizeof dp);
int id = 0;
dp[0][0] = 0;
int lim = 0, newc, add;
for(int i = n; i >= 1; i--)
{
id ^= 1;
// cout << lim << "\n";
for(int j = 0; j <= lim; j++)
dp[id][j] = dp[id ^ 1][j];
for(int j = (!a[i].type ? a[i].c : 0); j <= lim; j++)
{
if(!a[i].type)
{
newc = j - a[i].c;
add = a[i].v;
}
else
{
newc = j + a[i].c;
add = -a[i].v;
}
dp[id][newc] = max(dp[id][newc], dp[id ^ 1][j] + add);
// cout << n - i << " " << newc << " " << dp[id][newc] << "\n";
}
if(a[i].type) lim += a[i].c;
}
long long ans = 0;
for(int i = 0; i <= lim; i++) ans = max(ans, dp[id][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... |