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> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define ckmin(a, b) a = min(a, b)
#define ckmax(a, b) a = max(a, b)
#define int long long
const int maxn = 1e5 + 5;
const ll INF = 1e18;
struct info{
int c, f, v, t;
info(){}
info(int _c, int _f, int _v, int _t) : c(_c), f(_f), v(_v), t(_t){}
bool operator < (const info& other) const{
return f < other.f || (f == other.f && t < other.t);
}
bool operator > (const info& other) const{
return f > other.f || (f == other.f && t > other.t);
}
};
signed main(void){
fastio;
int n;
cin>>n;
vector<info> a;
for(int i = 0; i < n; i++){
int c, f, v;
cin>>c>>f>>v;
a.pb(info(c, f, v, 1));
}
int m;
cin>>m;
for(int i = 0; i < m; i++){
int c, f, v;
cin>>c>>f>>v;
a.pb(info(c, f, v, -1));
}
sort(a.begin(), a.end(), greater<info>());
vector<int> dp(maxn + 1, -INF);
dp[0] = 0;
for(auto [c, f, v, t] : a){
if(t == 1){
for(int i = maxn - 1; i >= c; i--) dp[i] = max(dp[i], dp[i - c] - v);
}
else{
for(int i = 0; i < maxn - c; i++) dp[i] = max(dp[i], dp[i + c] + v);
}
}
int ans = 0;
for(int i = 0; i < maxn; i++) ans = max(ans, dp[i]);
cout<<ans<<"\n";
}
# | 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... |