This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Source: https://oj.uz/problem/view/CEOI18_clo
//
#include "bits/stdc++.h"
using namespace std;
#define s second
#define f first
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;
typedef vector<ll> vi;
#define FOR(i, a, b) for (ll i = (a); i<b; i++)
vector<vi> changes; // clock rate, change in cores, change in price
const ll N = 2e3 + 1;
ll dp[2][50 * N];
const ll INF = 1e18;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin >> n;
FOR(i, 0, n) {
ll c, f, v;
cin >> c >> f >> v;
changes.pb({f, c, -v});
}
ll m;
cin >> m;
FOR(i, 0, m) {
ll c, f, v;
cin >> c >> f >> v;
changes.pb({f, -c, v});
}
sort(changes.rbegin(), changes.rend());
FOR(i, 0, 50*N) dp[0][i] = dp[1][i] = -INF;
dp[0][0] = 0;
ll ans = 0;
FOR(i, 0, changes.size()) {
ll cur = i %2;
ll oth = (i + 1) % 2;
FOR(j, 0, 50*N) {
dp[oth][j] = max(dp[oth][j], dp[cur][j]);
if (j + changes[i][1] >= 50*N || j + changes[i][1] < 0) {
dp[cur][j] = -INF;
continue;
}
// if (dp[cur][j] > 0) cout << " " << i << ' ' << j << endl;
dp[oth][j + changes[i][1]] = max(dp[oth][j + changes[i][1]], dp[cur][j] + changes[i][2]);
dp[cur][j] = -INF;
}
}
FOR(i, 0, 50*N) {
// if (dp[changes.size() % 2][i] > 0) cout << i << ' ' << dp[changes.size() % 2][i] << endl;
ans = max(ans, dp[changes.size() % 2][i]);
}
cout << ans << endl;
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:19:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | #define FOR(i, a, b) for (ll i = (a); i<b; i++)
......
59 | FOR(i, 0, changes.size()) {
| ~~~~~~~~~~~~~~~~~~~~
clo.cpp:59:2: note: in expansion of macro 'FOR'
59 | FOR(i, 0, changes.size()) {
| ^~~
# | 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... |