제출 #1091096

#제출 시각아이디문제언어결과실행 시간메모리
10910964QT0RCloud Computing (CEOI18_clo)C++17
100 / 100
285 ms1616 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

struct computer{
	ll f;
	ll c;
	ll v;
};

computer wej[4003];
ll dp[100003];
ll oo=1e18;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	ll n,m;
	cin >> n;
	for (ll i = 0; i<n; i++){
		cin >> wej[i].c >> wej[i].f >> wej[i].v;
		wej[i].v=-wej[i].v;
	}
	cin >> m;
	for (ll i = n; i<n+m; i++){
		cin >> wej[i].c >> wej[i].f >> wej[i].v;
		wej[i].c=-wej[i].c;
	}
	sort(wej,wej+n+m,[](computer a, computer b){return (a.f==b.f?a.c>b.c:a.f>b.f);});
	fill(dp,dp+100002,-oo);
	dp[0]=0;
	for (ll i = 0; i<n+m; i++){
		if (wej[i].c>0){
			for (ll j = 100000-wej[i].c; j>=0; j--){
				dp[j+wej[i].c]=max(dp[j+wej[i].c],dp[j]+wej[i].v);
			}
		}
		else{
			for (ll j = -wej[i].c; j<=100000; j++){
				dp[j+wej[i].c]=max(dp[j+wej[i].c],dp[j]+wej[i].v);
			}
		}
	}
	ll ans=0;
	for (ll i = 0; i<=100000; i++)ans=max(ans,dp[i]);
	cout << ans << '\n';
}
#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...