이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n, m;
struct Elem {
int cores, frecv;
long long value;
bool operator < (const Elem A) const {
return frecv > A.frecv;
}
};
Elem a[4005];
long long dp1[200005], dp2[200005];
int main()
{
cin >> n;
int sum_c = 0;
for (int i = 1; i <= n; i++) {
int c, f, v;
cin >> c >> f >> v;
a[i] = {c, f, -v};
sum_c += c;
}
cin >> m;
for (int i = 1; i <= m; i++) {
int c, f, v;
cin >> c >> f >> v;
a[n + i] = {-c, f, v};
}
n = m + n;
sort(a + 1, a + n + 1);
/**
for (int i = 1; i <= n; i++)
cout << a[i].cores << " " << a[i].frecv << " " << a[i].value << "\n";*/
for (int i = 0; i <= sum_c; i++)
dp1[i] = LLONG_MIN, dp2[i] = LLONG_MIN;
for (int i = 1; i <= n; i++) {
///if (a[i].cores > 0) {
for (int j = sum_c; j >= 0; j--)
if (dp1[j] > LLONG_MIN && j + a[i].cores <= sum_c && j + a[i].cores >= 0) {
dp2[j + a[i].cores] = max({dp2[j + a[i].cores], dp1[j] + a[i].value, dp1[j + a[i].cores]});
}
if (a[i].cores >= 0)
dp2[a[i].cores] = max({dp2[a[i].cores], a[i].value, dp1[a[i].cores]});
//}
/**
else {
for (int j = 0; j <= sum_c; j++)
if (dp1[j] > LLONG_MIN && j + a[i].cores >= 0) {
dp2[j + a[i].cores] = max({dp2[j + a[i].cores], dp1[j] + a[i].value, dp1[j + a[i].cores]});
}
///dp2[a[i].cores] = max({dp2[a[i].cores], a[i].value, dp1[a[i].cores]});
}*/
/**
if (i == 6)
cout << a[i].value << " " << dp2[2] << "!!!!!\n\n";
for (int j = 0; j <= sum_c; j++)
cout << dp2[j] << " ";
cout << "\n";
*/
for (int j = 0; j <= sum_c; j++)
dp1[j] = dp2[j], dp2[j] = LLONG_MIN;
}
long long ans = 0;
for (int i = 0; i <= sum_c; i++)
ans = max(ans, dp1[i]);
cout << ans << "\n";
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... |