| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1321498 | NgTrung2217 | Cloud Computing (CEOI18_clo) | C++20 | 587 ms | 1460 KiB |
#include <bits/stdc++.h>
#define task ""
#define ff first
#define ss second
using namespace std;
using ll = long long;
using pii = pair <int, int>;
const char el = '\n';
const char sp = ' ';
const int maxN = 100005;
const ll INF = 1e16;
struct Item
{
ll c, f, v;
int type;
};
int n, m;
ll dp[maxN + 5];
vector <Item> v;
bool compareItems (const Item &a, const Item &b)
{
if (a.f == b.f) return a.type < b.type;
return a.f > b.f;
}
void solve ()
{
if (!(cin >> n)) return;
for (int i = 0;i < n;++i)
{
ll c, f, v_val;
cin >> c >> f >> v_val;
v.push_back({c, f, v_val, 0});
}
cin >> m;
for (int i = 0;i < m;++i)
{
ll c, f, v_val;
cin >> c >> f >> v_val;
v.push_back({c, f, v_val, 1});
}
sort(v.begin(), v.end(), compareItems);
for (int i = 0;i <= maxN;++i) dp[i] = -INF;
dp[0] = 0;
ll ans = 0;
for (auto &it : v)
{
if (it.type == 1)
{
for (int i = 0;i + it.c <= maxN;++i)
{
dp[i] = max(dp[i], dp[i + (int)it.c] + it.v);
}
}
else
{
for (int i = maxN;i >= it.c;--i)
{
dp[i] = max(dp[i], dp[i - (int)it.c] - it.v);
}
}
for (int i = 0;i <= maxN;++i) ans = max(ans, dp[i]);
}
cout << ans << el;
}
int main ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if (fopen(task ".inp", "r"))
{
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
solve();
return 0;
}
컴파일 시 표준 에러 (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... | ||||
