이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
constexpr int CORESMAX = 50 * 2000 + 5;
constexpr LL INF = 1LL * 1e16;
struct Computer {
int cores;
int freq;
int value;
int ind;
bool operator < (const Computer &other) const {
return (freq > other.freq || (freq == other.freq && ind < other.ind));
}
};
int N, M;
vector <Computer> E;
LL dp[CORESMAX];
int Total_Cores;
void Read () {
cin >> N;
for (int i = 1; i <= N; ++ i ) {
Computer C;
cin >> C.cores >> C.freq >> C.value;
C.ind = -1;
Total_Cores += C.cores;
E.push_back(C);
}
cin >> M;
for (int i = 1; i <= M; ++ i ) {
Computer C;
cin >> C.cores >> C.freq >> C.value;
C.ind = 1;
E.push_back(C);
}
sort(E.begin(), E.end());
}
void Solve () {
for (int i = 0; i <= Total_Cores; ++ i )
dp[i] = -INF;
dp[0] = 0;
for (auto it : E) {
if (it.ind == -1) {
for (int i = Total_Cores; i >= it.cores; -- i ) {
if (dp[i - it.cores] == -INF) continue;
dp[i] = max(dp[i], dp[i - it.cores] - it.value);
}
}
else {
for (int i = 0; i <= Total_Cores - it.cores; ++ i ) {
if (dp[i + it.cores] == -INF) continue;
dp[i] = max(dp[i], dp[i + it.cores] + it.value);
}
}
}
LL ans = 0;
for (int i = 0; i <= Total_Cores; ++ i )
ans = max(ans, dp[i]);
cout << ans << '\n';
}
int main () {
Read();
Solve();
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... |