제출 #941215

#제출 시각아이디문제언어결과실행 시간메모리
941215vjudge1Cloud Computing (CEOI18_clo)C++17
100 / 100
399 ms1372 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()

template<class S, class T>
bool chmin(S &a, const T &b) {
	return a > b ? (a = b) == b : false;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
	return a < b ? (a = b) == b : false;
}
const int inf = 1e18;

signed main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	int n; cin >> n;
    vector<array<int, 4>> vec;
	for (int i = 0; i < n; ++i) {
		int c, f, v; cin >> c >> f >> v;
        vec.push_back({f, 1, v, c});
	}
	int m; cin >> m;
	for (int i = 0; i < m; ++i) {
		int c, f, v; cin >> c >> f >> v;
        vec.push_back({f, 0, v, c});
	}
	sort(all(vec));
    vector<int> dp(50 * n + 1, -inf);
    dp[0] = 0;
    while (!vec.empty()) {
        auto [C, V] = make_pair(vec.back()[3], vec.back()[2]);
        if (vec.back()[1]) {
            for (int i = 50 * n - C; i >= 0; --i) {
                chmax(dp[i + C], dp[i] - V);
            }
        } else {
            for (int i = C; i <= 50 * n; ++i) {
                chmax(dp[i - C], dp[i] + V);
            }
        }
        vec.pop_back();
    }
    cout << *max_element(all(dp));
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...