Submission #1075932

#TimeUsernameProblemLanguageResultExecution timeMemory
1075932MinaRagy06Two Dishes (JOI19_dishes)C++17
10 / 100
582 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define SZ(x) (int) x.size() int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m; cin >> n >> m; array<ll, 3> a[n + 1], b[m + 1]; ll prfa[n + 1]{}, prfb[m + 1]{}; for (int i = 1; i <= n; i++) { cin >> a[i][0] >> a[i][1] >> a[i][2]; prfa[i] = prfa[i - 1] + a[i][0]; } for (int i = 1; i <= m; i++) { cin >> b[i][0] >> b[i][1] >> b[i][2]; prfb[i] = prfb[i - 1] + b[i][0]; } ll dp[n + 1][m + 1]{}; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { if (i == 0 && j == 0) continue; // cout << i << ' ' << j << endl; dp[i][j] = -1e18; if (i) { dp[i][j] = max(dp[i][j], dp[i - 1][j] + (prfa[i] + prfb[j] <= a[i][1]) * a[i][2]); } if (j) { dp[i][j] = max(dp[i][j], dp[i][j - 1] + (prfa[i] + prfb[j] <= b[j][1]) * b[j][2]); } } } cout << dp[n][m] << '\n'; 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...