Submission #1313428

#TimeUsernameProblemLanguageResultExecution timeMemory
1313428muhammad-ahmadCloud Computing (CEOI18_clo)C++20
54 / 100
341 ms3916 KiB
// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <set>
#include <deque>
#include <numeric>
#include <stack>
#include <chrono>
using namespace std;

void fast_io() {
	// freopen("", "r", stdin);
	// freopen("", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie();
	cout.tie();
	cout << setprecision(9);
}

#define int long long
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second

const int N = 2e3 + 5;

struct order{
	int cores = 0;
	int speed = 0;
	int price = 0;
};

bool comp(order a, order b){
	return (a.speed >= b.speed);
}

void solve() {
	int n, m; cin >> n;
	vector<order> T;
	for (int i = 1; i <= n; i++){
		order temp;
		cin >> temp.cores >> temp.speed >> temp.price;
		temp.price *= -1;
		T.push_back(temp);
	}
	cin >> m;
	for (int i = 1; i <= m; i++){
		order temp;
		cin >> temp.cores >> temp.speed >> temp.price;
		temp.cores *= -1;
		T.push_back(temp);
	}
	sort(all(T), comp);
	
	vector<int> dp(N * 105, 0), lst(N * 105, 0);
	
	for (int i = 1; i < N * 105; i++) lst[i] = dp[i] = -1e18;
	for (int i = 0; i < n + m; i++){
		int rate = T[i].speed, core = T[i].cores, cost = T[i].price;
		for (int j = 0; j <= n * 50; j++){
			dp[j] = lst[j];
			if (j - core >= 0) dp[j] = max(dp[j], lst[j - core] + cost);
		}
		swap(dp, lst);
	}
	int ans = 0;
	for (auto i : lst) ans = max(ans, i);
	cout << ans << endl;
}

signed main() {
	fast_io();
	srand(chrono::steady_clock::now().time_since_epoch().count());
	int tc = 1;
	// cin >> tc;
	while (tc--) solve();
	return 0;
}


#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...