Submission #973096

#TimeUsernameProblemLanguageResultExecution timeMemory
973096DAleksaTwo Dishes (JOI19_dishes)C++17
10 / 100
784 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; int a[n + 1], b[m + 1], s[n + 1], t[m + 1], p[n + 1], q[m + 1]; int x[n + 1], y[m + 1]; for(int i = 1; i <= n; i++) cin >> a[i] >> s[i] >> p[i]; for(int i = 1; i <= m; i++) cin >> b[i] >> t[i] >> q[i]; x[0] = 0; y[0] = 0; for(int i = 1; i <= n; i++) x[i] = x[i - 1] + a[i]; for(int i = 1; i <= m; i++) y[i] = y[i - 1] + b[i]; int dp[n + 1][m + 1]; dp[0][0] = 0; for(int i = 0; i <= n; i++) { for(int j = 0; j <= m; j++) { if(i == 0 && j == 0) continue; dp[i][j] = -1e18; if(i > 0) dp[i][j] = max(dp[i][j], dp[i - 1][j] + (x[i] + y[j] <= s[i]) * p[i]); if(j > 0) dp[i][j] = max(dp[i][j], dp[i][j - 1] + (x[i] + y[j] <= t[j]) * q[j]); } } cout << dp[n][m]; return 0; }
#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...