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;
// Shortcuts for common operations
#define pb push_back
#define ppb pop_back
#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define endl "\n"
// Type definitions for convenience
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef unordered_set<int> usi;
typedef unordered_map<int, int> umii;
// Debugging macros
#define debug(x) cerr << #x << " = " << (x) << '\n'
#define debug_vector(v) _debug_vector(#v, v)
template<typename T>
void _debug_vector(const string& name, const vector<T>& a) {
cerr << name << " = [ ";
for(const auto &x : a) cerr << x << ' ';
cerr << "]\n";
}
// I/O redirection for local testing
#define iofile(io) \
freopen((io + ".in").c_str(), "r", stdin); \
freopen((io + ".out").c_str(), "w", stdout);
// delta for floodfill
vi dx = {0, 1, 0, -1};
vi dy = {1, 0, -1, 0};
// extended deltas for floodfill
vi edx = {0, 1, 0, -1, 1, 1, -1, -1};
vi edy = {1, 0, -1, 0, 1, -1, 1, -1};
// Common outputs
void yes() { cout << "YES" << '\n'; }
void no() { cout << "NO" << '\n'; }
// cin.tie(0)->sync_with_stdio(0);
#define C s.f
#define V s.s
vector<ll>dp;
vector<pair<pii, pii>>tab;
int n, m;
void fx() {
// Functionality for fx
cin >> n;
int c, f, v;
for(int i = 0; i < n; i++){
cin >> c >> f >> v;
tab.pb({{-f, -1}, {c, v}});
}
cin >> m;
dp.assign(50*max(n,m) +1, -100000000000000);
for(int i = 0; i < m; i++){
cin >> c >> f >> v;
tab.pb({{-f, 1}, {c, v}});
}
sort(all(tab));
dp[0] = 0;
for(int i = 0; i < n+m; i++){
if(tab[i].f.s == -1){
//buy computer?
for(int j = 50 * max(n, m) - tab[i].C; j >= 0; j--) dp[j + tab[i].C] = max(dp[j + tab[i].C], dp[j] - tab[i].V);
}else{
//take customer?
for(int j = 0; j <= 50 * max(n, m) - tab[i].C; j++) dp[j] = max(dp[j], dp[j + tab[i].C] + tab[i].V);
}
}
cout << *max_element(all(dp)) << endl;
}
int main() {
// Uncomment the following lines for file I/O
// iofile(string("hello"));
// Uncomment the following lines for multiple test cases
// int t; cin >> t;
// while(t--) fx();
// Single test case
fx();
return 0;
}
# | 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... |