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 LCBorz \
ios_base::sync_with_stdio(false); \
cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
#define x first
#define y second
const int N=100005;
const int INF=1e18;
struct qry{
int c,f,v;
bool operator<(const qry &o){
return f!=o.f?f>o.f:c>o.c;
}
};
int32_t main() {
LCBorz;
int n;cin>>n;
vector<qry> v;
for(int i=0;i<n;i++){
int a,b,c;cin>>a>>b>>c;
v.push_back({a,b,c});
}
int m;cin>>m;
for(int i=0;i<m;i++){
int a,b,c;cin>>a>>b>>c;
v.push_back({-a,b,c});
}
sort(all(v));
vector<int> dp(N,-INF);
dp[0]=0;
for(int i=0;i<n+m;i++){
auto [c,f,val]=v[i];
if(c>0){
for(int j=N-1;j>=c;j--){
dp[j]=max(dp[j],dp[j-c]-val);
}
}
else{
c=-c;
for(int j=0;j+c<N;j++){
dp[j]=max(dp[j],dp[j+c]+val);
}
}
}
int ans=0;
for(int i=0;i<N;i++){
ans=max(ans,dp[i]);
}
cout<<ans<<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... |