제출 #673635

#제출 시각아이디문제언어결과실행 시간메모리
673635vjudge1Cloud Computing (CEOI18_clo)C++14
36 / 100
821 ms3540 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pb push_back #define all(val) val.begin(), val.end() #define db(val) "[" #val " = " << (val) << "] " const int N = 2005; const int C = 50; struct Node { int c, f, w; bool operator < (const Node &o) { return f > o.f; } Node(int c, int f, int w): c(c), f(f), w(w) {} }; ll dp[2][100 * N]; int n, m; vector<Node> a; void MAX(ll &a, ll b) { if (a < b) a = b; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1, c, f, w; i <= n; i++) { cin >> c >> f >> w; a.pb(Node(c, f, -w)); } cin >> m; for (int i = 1, c, f, w; i <= m; i++) { cin >> c >> f >> w; a.pb(Node(-c, f, w)); } sort(all(a)); memset(dp[0], -1, sizeof dp[0]); dp[0][0] = 0; for (int i = 0; i < n + m; i++) { int cur = i & 1, nxt = cur ^ 1; memset(dp[nxt], -63, sizeof dp[nxt]); for (int j = 0; j <= (n + m) * C; j++) if (dp[cur][j] != -1) { MAX(dp[nxt][j], dp[cur][j]); if (j + a[i].c >= 0) MAX(dp[nxt][j + a[i].c], dp[cur][j] + a[i].w); } } ll res = 0; for (int j = 0; j <= (n + m) * C; j++) MAX(res, dp[(n + m) & 1][j]); cout << res; }
#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...