이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |