# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
861037 | guagua0407 | Two Dishes (JOI19_dishes) | C++17 | 505 ms | 1048576 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const int mxn=1e6+5;
ll a[mxn],S[mxn],Q[mxn];
ll b[mxn],T[mxn],P[mxn];
int pa[mxn],pb[mxn];
vector<int> qa[mxn],qb[mxn];
int n,m;
int main() {_
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i]>>S[i]>>P[i];
a[i]+=a[i-1];
}
for(int i=1;i<=m;i++){
cin>>b[i]>>T[i]>>Q[i];
b[i]+=b[i-1];
}
for(int i=1;i<=n;i++){
int pos=upper_bound(b,b+m+1,S[i]-a[i])-b-1;
pa[i]=pos;
if(pos>=0) qa[pos].push_back(i);
}
for(int i=1;i<=m;i++){
int pos=upper_bound(a,a+n+1,T[i]-b[i])-a-1;
pb[i]=pos;
if(pos>=0) qb[pos].push_back(i);
}
vector<vector<ll>> dp(n+1,vector<ll>(m+1,-1e18));
dp[0][0]=0;
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
if(i>0) dp[i][j]=max(dp[i][j],dp[i-1][j]+(pa[i]>=j?P[i]:0));
if(j>0) dp[i][j]=max(dp[i][j],dp[i][j-1]+(pb[j]>=i?Q[j]:0));
}
}
cout<<dp[n][m];
return 0;
}
//maybe its multiset not set
Compilation message (stderr)
# | 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... |