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 int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
//Don't open the standings during contests.
const int mxn=2005;
vector<int>a(mxn),s(mxn),p(mxn),b(mxn),t(mxn),q(mxn),pre(mxn),pre2(mxn);
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i]>>s[i]>>p[i];
pre[i]=pre[i-1]+a[i];
}
for(int i=1;i<=m;i++){
cin>>b[i]>>t[i]>>q[i];
pre2[i]=pre2[i-1]+b[i];
}
vector<vector<int>>dp(n+1,vector<int>(m+1,-8e18));
dp[0][0]=0;
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
if(i)chmax(dp[i][j],dp[i-1][j]+(pre[i]+pre2[j]<=s[i])*p[i]);
if(j)chmax(dp[i][j],dp[i][j-1]+(pre[i]+pre2[j]<=t[j])*q[j]);
}
}
cout<<dp[n][m]<<'\n';
}
/*
input:
*/
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |