# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1264398 | mingga | Cloud Computing (CEOI18_clo) | C++20 | 536 ms | 3616 KiB |
// Author: caption_mingle
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 4005;
const int M = 2e5 + 7;
int n, m;
ll dp[2][M];
struct dak {
int c, f, v;
bool operator < (const dak& o) const {
if(f == o.f) return v < o.v;
return f > o.f;
}
} a[N];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n;
int totc = 0;
for(int i = 1; i <= n; i++) {
int c, f, v; cin >> c >> f >> v;
a[i] = {c, f, -v};
totc += c;
}
cin >> m;
for(int i = 1; i <= m; i++) {
int c, f, v; cin >> c >> f >> v;
a[i + n] = {-c, f, v};
}
n += m;
sort(a + 1, a + n + 1);
memset(dp, -0x3f, sizeof dp);
dp[0][0] = 0;
// for(int i = 1; i <= n; i++) {
// cerr << a[i].c << ' ' << a[i].f << ' ' << a[i].v << ln;
// }
for(int i = 1; i <= n; i++) {
int id = i & 1;
for(int j = 0; j <= totc; j++) {
dp[id][j] = dp[id ^ 1][j];
}
for(int j = 0; j <= totc; j++) {
int nc = j + a[i].c;
if(nc >= 0) dp[id][nc] = max(dp[id][nc], dp[id ^ 1][j] + a[i].v);
}
// for(int j = 0; j <= totc; j++)
// cerr << i << ' ' << j << ' ' << dp[id][j] << ln;
}
cout << * max_element(dp[n & 1], dp[n & 1] + n + 1) << ln;
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
컴파일 시 표준 에러 (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... |