이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF = -1e18;
const int MOD = 1e9 + 7;
int n, m;
ll dp[100002];
struct lol{
int c, f, x;
bool operator < (const lol &other) {
if (f == other.f)
return c > other.c;
return f > other.f;
}
} v[4002];
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> v[i].c >> v[i].f >> v[i].x;
v[i].x = -v[i].x;
}
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> v[i + n].c >> v[i + n].f >> v[i + n].x;
v[i + n].c = -v[i + n].c;
}
sort(v + 1, v + n + m + 1);
fill(dp, dp + 50 * n + 1, INF);
dp[0] = 0;
for (int i = 1; i <= n + m; i++) {
if (v[i].c > 0) {
for (int j = 50 * n - v[i].c; j >= 0; j--)
dp[j + v[i].c] = max(dp[j] + v[i].x, dp[j + v[i].c]);
}
else {
for (int j = -v[i].c; j <= 50 * n; j++) {
dp[j + v[i].c] = max(dp[j + v[i].c], dp[j] + v[i].x);
}
}
}
ll ans = 0;
for (int i = 0; i <= 50 * n; i++)
ans = max(ans, dp[i]);
cout << ans;
return 0;
}
# | 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... |