제출 #1191817

#제출 시각아이디문제언어결과실행 시간메모리
1191817sunboiCloud Computing (CEOI18_clo)C++20
0 / 100
243 ms8184 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n; cin >> n; vector<pair<int, int>> a(n); for (int i = 0; i < n; i++){ int c; cin >> c; cin >> a[i].first >> a[i].second; } sort(a.begin(), a.end()); int m; cin >> m; vector<pair<int, int>> b(m); for (int i = 0; i < m; i++){ int c; cin >> c; cin >> b[i].first >> b[i].second; } sort(b.begin(), b.end()); vector<vector<vector<int>>> dp(n + 1, vector<vector<int>> (m + 1, vector<int> (2, -1e18))); for (int i = 0; i < n; i++){ dp[i][0][0] = 0; if (a[i].first >= b[0].first){ dp[i][0][1] = b[0].second - a[i].second; } } for (int j = 1; j < m; j++){ for (int i = 0; i < n; i++){ for (int l = 0; l <= i; l++){ if (dp[l][j - 1][0] != -1e18) dp[i][j][0] = max(dp[i][j][0], dp[l][j - 1][0]); if (dp[l][j - 1][1] != -1e18 && l < i) dp[i][j][0] = max(dp[i][j][0], dp[l][j - 1][1]); if (a[i].first >= b[j].first) { if (dp[l][j - 1][0] != -1e18) dp[i][j][1] = max(dp[i][j][1], dp[l][j - 1][0] + b[j].second - a[i].second); if (dp[l][j - 1][1] != -1e18 && l < i) dp[i][j][1] = max(dp[i][j][1], dp[l][j - 1][1] + b[j].second - a[i].second); if (dp[l][j - 1][1] != -1e18 && l == i) dp[i][j][1] = max(dp[i][j][1], dp[l][j - 1][1]); } } } } /*for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ cout << dp[i][j][0] << ' '; } cout << endl; } cout << endl; for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ cout << dp[i][j][1] << ' '; } cout << endl; } cout << endl;*/ int ans = 0; for (int i = 0; i < n; i++){ ans = max(ans, dp[i][m - 1][0]); ans = max(ans, dp[i][m - 1][1]); } cout << ans << endl; }
#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...