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;
#define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define FOD(i,a,b) for(int i = a; i >= b; i--)
#define int long long
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define lcm(a,b) (a*b)/__gcd(a,b)
#define ii pair<int,int>
#define iii pair<int,pair<int,int>>
#define iv pair<pair<int,int>,pair<int,int>>
const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 105;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,1,0,-1};
const int dxx[] = {-1,-1,0,1,1,1,0,-1};
const int dyy[] = {0,1,1,1,0,-1,-1,-1};
struct dat
{
int c, f, v;
};
bool cmp(dat a, dat b)
{
return a.f != b.f ? a.f > b.f : a.v < b.v;
}
int n, sum, m;
vector<dat> a;
int dp[N][2];
void solve()
{
sort(a.begin(), a.end(), cmp);
FOR(i,1,sum)
dp[i][0] = -INF;
for(int i = 0; i < a.size(); i++)
{
for(int j = 0; j <= sum; j++)
dp[j][1] = dp[j][0];
for(int j = 0; j <= sum; j++)
{
int pre = j - a[i].c;
if(pre >= 0 && pre <= sum)
dp[j][1] = max(dp[j][1], dp[pre][0] + a[i].v);
}
for(int j = 0; j <= sum; j++)
dp[j][0] = dp[j][1];
}
int ans = -INF;
FOR(i,1,sum)
ans = max(ans, dp[i][0]);
cout << ans;
}
void input()
{
//freopen("TEST.INP", "r", stdin);
//freopen("TEST.OUT", "w", stdout);
cin >> n;
FOR(i,1,n)
{
int c, f, v;
cin >> c >> f >> v;
a.pb({c,f,-v});
sum += c;
}
cin >> m;
FOR(i,1,m)
{
int c, f, v;
cin >> c >> f >> v;
a.pb({-c,f,v});
}
}
signed main()
{
faster
input();
solve();
}
Compilation message (stderr)
clo.cpp: In function 'void solve()':
clo.cpp:46:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<dat>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 0; i < a.size(); i++)
| ~~^~~~~~~~~~
# | 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... |