# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
482994 | Lam_lai_cuoc_doi | Cloud Computing (CEOI18_clo) | C++17 | 308 ms | 1228 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>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
void read(T &x)
{
x = 0;
register int c;
while ((c = getchar()) && (c > '9' || c < '0'))
;
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
}
constexpr bool typetest = 0;
constexpr int N = 2e3 + 5;
constexpr ll Inf = 1e17;
struct Object
{
int c, f, v;
bool seller;
bool operator<(const Object &a) const
{
return f < a.f || (f == a.f && !seller && a.seller);
}
} a[N * 2];
ll dp[N * 50];
int n, m;
void Read()
{
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> a[i].c >> a[i].f >> a[i].v;
a[i].seller = 1;
}
cin >> m;
for (int i = n + 1; i <= n + m; ++i)
cin >> a[i].c >> a[i].f >> a[i].v;
}
inline void Max(ll &x, ll y)
{
if (x < y)
x = y;
}
void Solve()
{
sort(a + 1, a + m + n + 1);
fill_n(dp, N * 50, -Inf);
dp[0] = 0;
for (int i = 1, cnt(0); i <= m + n; ++i)
{
if (a[i].seller)
{
for (int j = 0; j <= cnt; ++j)
Max(dp[max(0, j - a[i].c)], dp[j] - a[i].v);
}
else
{
for (int j = cnt; ~j; --j)
Max(dp[j + a[i].c], dp[j] + a[i].v);
cnt += a[i].c;
}
}
cout << dp[0];
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("xor.INP", "r"))
{
freopen("xor.inp", "r", stdin);
freopen("xor.out", "w", stdout);
}
int t(1);
if (typetest)
cin >> t;
for (int _ = 1; _ <= t; ++_)
{
// cout << "Case #" << _ << ": ";
Read();
Solve();
}
// cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
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... |