Submission #681481

#TimeUsernameProblemLanguageResultExecution timeMemory
681481penguin133Cloud Computing (CEOI18_clo)C++17
0 / 100
135 ms262144 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

vector <pii> stuf, ord;
int n, m, memo[2001][2001][51];
bool cmp(pii a, pii b){
	return a.se.fi < b.se.fi;
}
int dp(int x, int y, int rem){
	//cerr << x << " " << y << " " << rem << '\n';
	if(x < 0 || y < 0)return 0;
	assert(x >= 0 && y >= 0 && rem >= 0);
	if(memo[x][y][rem] != -1e18)return memo[x][y][rem];
	if(stuf[x].se.fi < ord[y].se.fi)return memo[x][y][rem] = dp(x, y - 1, (y > 0 ? ord[y-1].fi : 0));
	int ans = dp(x - 1, y, rem), tmp = rem - stuf[x].fi, val = -stuf[x].se.se;
	int y2 = y;
	while(tmp <= 0 && y2 >= 0){
		val += ord[y2].se.se;
		y2--;
		if(y2 >= 0)tmp += ord[y2].fi;
		else tmp = 0;
		//cerr << tmp << " " << y << '\n';
	}
	//cerr << x << " " << y << " " << rem << '\n';
	return memo[x][y][rem] = max(ans, dp(x - 1, y2, tmp) + val);
}

void solve(){
	cin >> n;
	for(int i=1;i<=n;i++){
		int a, b, c; cin >> a >> b >> c;
		stuf.push_back({a, {b, c}});
	}
	cin >> m;
	for(int i=0;i<=n;i++)for(int j=0;j<=m;j++)for(int k=0;k<=50;k++)memo[i][j][k] = -1e18;
	for(int i=1;i<=m;i++){
		int a, b, c; cin >> a >> b >> c;
		ord.push_back({a, {b, c}});
	}
	sort(stuf.begin(), stuf.end(), cmp);
	sort(ord.begin(), ord.end(), cmp);
	cout << dp(n-1, m-1, ord[m-1].fi);
	//cout << dp(1, 1, 2) << '\n';
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message (stderr)

clo.cpp:55:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   55 | main(){
      | ^~~~
#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...