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;
#define F first
#define S second
#define all(a) a.begin(), a.end()
#define pb push_back
#define int long long
typedef long long ll;
typedef pair<int, int> ii;
void print() {cerr << '\n';} template<typename T1, typename... T2>
void print(T1 a, T2... b) {cerr << a << ' ', print(b...);}
const int N = 2000 + 5;
vector<ll> last, curr;
int n, m;
struct events
{
ll c, f, v, type;
};
vector<events> e;
bool cmp(const events &a, const events &b)
{
return (a.f != b.f ? a.f > b.f : a.type < b.type);
}
void solve()
{
int cores = 0;
cin >> n;
for(int i = 1; i <= n; i++)
{
int c, f, v;
cin >> c >> f >> v;
e.pb({c, f, v, -1});
cores += c;
}
cin >> m;
for(int i = 1; i <= m; i++)
{
int c, f, v;
cin >> c >> f >> v;
e.pb({c, f, v, 1});
}
sort(all(e), cmp);
last.assign(cores + 5, -1e17);
curr.assign(cores + 5, -1e17);
last[0] = curr[0] = 0;
for(const events &x : e)
{
curr = last;
if(x.type == -1)
{
for(int i = x.c; i <= cores; i++)
curr[i] = max(curr[i], last[i - x.c] - x.v);
}
else
{
for(int i = 0; i <= cores - x.c; i++)
curr[i] = max(curr[i], last[i + x.c] + x.v);
}
last.swap(curr);
}
cout << *max_element(all(last));
}
signed main()
{
if(fopen("test.inp", "r"))
{
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
cin.tie(0) -> sync_with_stdio(0);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
77 | freopen("test.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
78 | freopen("test.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |