제출 #583597

#제출 시각아이디문제언어결과실행 시간메모리
583597BhavayGoyalCloud Computing (CEOI18_clo)C++14
100 / 100
818 ms2772 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define int long long #define ld long double #define ar array #define vi vector<int> #define vii vector<vector<int>> #define pii pair<int, int> #define pb push_back #define all(x) x.begin(), x.end() #define f first #define s second const int MOD = 1e9+7; const int inf = 1e9; const int linf = 1e18; const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1}; const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1}; // -------------------------------------------------- Main Code -------------------------------------------------- int n, m; array<int, 3> arr[4001]; void sol() { cin >> n; int ct = 0; for (int i = 0; i < n; i++) { cin >> arr[i][0] >> arr[i][1] >> arr[i][2]; ct += arr[i][0]; arr[i][2] *= -1; } cin >> m; for (int i = 0; i < m; i++) { cin >> arr[i+n][0] >> arr[i+n][1] >> arr[i+n][2]; arr[i+n][0] *= -1; } sort (arr, arr+n+m, [](array<int, 3> a, array<int, 3> b) {return (a[1] != b[1]?a[1] > b[1]:a[0] > b[0]);}); vector<vector<int>> dp(2, vector<int>(ct+1, -linf)); dp[0][0] = 0; for (int i = 1; i <= n+m; i++) { for (int j = 0; j <= ct; j++) { dp[i&1][j] = max(dp[i&1][j], dp[1-(i&1)][j]); if (j-arr[i-1][0] >= 0 && j-arr[i-1][0] <= ct) dp[i&1][j] = max(dp[i&1][j], dp[1-(i&1)][j-arr[i-1][0]] + arr[i-1][2]); } } cout << *max_element(dp[(n+m)&1].begin(), dp[(n+m)&1].end()); } signed main () { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { sol(); } 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...