# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
827341 | PanosPask | Cloud Computing (CEOI18_clo) | C++14 | 88 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const ll INF = 1e18;
struct Event {
int profit_change;
int core_change;
int rate;
bool operator < (Event b) {
if (this->rate == b.rate)
return this->core_change < b.core_change;
return this->rate > b.rate;
}
};
int N, M;
// dp[i][j]: After the first i events (sorted in clock rate), maximum profit with at least j cores left over
vector<vector<ll>> dp;
vector<Event> events;
int main(void)
{
scanf("%d", &N);
for (int i = 0; i < N; i++) {
int c, f, v;
scanf("%d %d %d", &c, &f, &v);
events.pb({-v, c, f});
}
scanf("%d", &M);
for (int i = 0; i < M; i++) {
int c, f, v;
scanf("%d %d %d", &c, &f, &v);
events.pb({v, -c, f});
}
sort(events.begin(), events.end());
dp.resize(N + M + 1, vector<ll>(N * 50 + 1));
dp[0].assign(N * 50 + 1, -INF);
dp[0][0] = 0;
for (int i = 1; i <= N + M; i++) {
int cores = events[i - 1].core_change;
int v = events[i - 1].profit_change;
for (int j = 0; j <= N * 50; j++) {
dp[i][j] = dp[i - 1][j];
if (j - cores >= 0 && j - cores <= N * 50 && dp[i - 1][j - cores] != -INF)
dp[i][j] = max(dp[i][j], dp[i - 1][j - cores] + v);
}
}
ll ans = 0;
for (int i = 0; i < N * 50; i++)
ans = max(ans, dp[N + M][i]);
printf("%lld\n", ans);
}
Compilation message (stderr)
# | 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... |