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;
const long long infneg = -1e18;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
vector<pair<long long, pair<long long,long long>>> ve;
long long n;
cin>>n;
for(int i=1;i<=n;i++){
long long a, b, c;
cin>>a>>b>>c;
ve.push_back({b,{a,-c}});
}
cin>>n;
for(int i=1;i<=n;i++){
long long a, b, c;
cin>>a>>b>>c;
ve.push_back({b,{-a,c}});
}
sort(ve.begin(), ve.end());
vector<long long> dp(1e4*4+1,infneg);
dp[0]=0;
for(int j=ve.size()-1;j>=0;j--){
long long k=ve[j].second.first, p=ve[j].second.second;
if(k>0) for(int i=1e4*4-k;i>=0;i--)dp[k+i]=max(dp[k+i],dp[i]+p);
else for(int i=-k;i<=1e4*4;i++)dp[k+i]=max(dp[k+i],dp[i]+p);
}
long long ans = 0;
for (int i=0;i<=1e4*4;i++)ans=max(ans, dp[i]);
cout<<ans;
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... |