Submission #674080

#TimeUsernameProblemLanguageResultExecution timeMemory
674080beaconmcCloud Computing (CEOI18_clo)C++14
90 / 100
1754 ms2252 KiB
#include <bits/stdc++.h>

typedef long long ll;

#define FOR(i,x,y) for(ll i=x; i<y; i++)


using namespace std;

vector<ll> stuff[4001];

ll dp[2][100001];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	ll n;
	cin >> n;
	ll cur = 0;

	FOR(i,0,n){
		ll c,f,v;
		cin >> c >> f >> v;
		stuff[cur] = {-f, -v, c};
		cur++;
	}
	ll m;
	cin >> m;

	FOR(i,0,m){
		ll c,f,v;
		cin >> c >> f >> v;
		stuff[cur] = {-f, v, c};
		cur++;
	}
	sort(stuff, stuff+n+m);

	FOR(i,0,2){
		FOR(j,0,100001) dp[i][j] = -1000000000000000000;
	}
	dp[0][0] = 0;

	FOR(i,0,n+m){
		FOR(j,0,100001){
			if (stuff[i][1]<0){
				if (j+stuff[i][2] < 100000 ) dp[1][j+stuff[i][2]] = max(dp[1][j+stuff[i][2]], dp[0][j] + stuff[i][1]);
			}else{
				if (j-stuff[i][2]>=0 ) dp[1][j-stuff[i][2]] = max(dp[1][j-stuff[i][2]] , dp[0][j] + stuff[i][1]);
			}
			dp[1][j] = max(dp[1][j], dp[0][j]);
		}
		FOR(j,0,100001) dp[0][j] = dp[1][j], dp[1][j] = -1000000000000000000;
	}
	ll maxi = 0;

	FOR(i,0,100001){
		maxi = max(maxi, dp[0][i]);

	}
	cout << maxi << endl;

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