Submission #201829

#TimeUsernameProblemLanguageResultExecution timeMemory
201829theStaticMindTwo Dishes (JOI19_dishes)C++14
10 / 100
1584 ms1048580 KiB
#include<bits/stdc++.h> #define pb push_back #define ii pair<int,int> #define all(x) (x).begin(),(x).end() #define INF 100000000000000000 #define modulo 1000000007 #define mod 998244353 #define int long long int using namespace std; vector<int> Ta(1000005); vector<int> Tb(1000005); vector<int> Sa(1000005); vector<int> Sb(1000005); vector<int> Va(1000005); vector<int> Vb(1000005); vector<int> Pa(1000005, 0); vector<int> Pb(1000005, 0); int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("q.gir","r",stdin); // freopen("q.cik","w",stdout); int n, m; cin >> n >> m; for(int i = 1; i <= n; i++) cin >> Sa[i] >> Ta[i] >> Va[i]; for(int i = 1; i <= m; i++) cin >> Sb[i] >> Tb[i] >> Vb[i]; for(int i = 1; i <= n; i++) Pa[i] = Pa[i - 1] + Sa[i]; for(int i = 1; i <= m; i++) Pb[i] = Pb[i - 1] + Sb[i]; vector<vector<int> > dp(n + 1, vector<int> (m + 1, 0)); dp[0][0] = 0; for(int i = 0; i <= n; i++){ for(int j = 0; j <= m; j++){ int q = -INF, w = -INF; if(i > 0) q = dp[i - 1][j]; if(j > 0) w = dp[i][j - 1]; if(Pa[i] + Pb[j] <= Ta[i]){ dp[i][j] = max(dp[i][j], q + Va[i]); } if(Pa[i] + Pb[j] <= Tb[j]){ dp[i][j] = max(dp[i][j], w + Vb[j]); } dp[i][j] = max(dp[i][j], max(q, w)); } } cout << dp[n][m]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...