제출 #681496

#제출 시각아이디문제언어결과실행 시간메모리
681496penguin133Cloud Computing (CEOI18_clo)C++17
0 / 100
1000 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[251][251][751];
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(y <= 0)return 0;
	//assert(x >= 0 && 
	if(memo[x][y][rem] != -1e18)return memo[x][y][rem];
	//if(stuf[x-1].se.fi < ord[y-1].se.fi)return memo[x][y][rem] = dp(x, y - 1, rem);
	//cerr << x << " " <<y << " " << rem << " " << ord[y-1].fi << '\n';
	int ans = dp(x, y - 1, rem);
	if(x > 0)ans = max(ans, dp(x - 1, y, rem));
	if(x > 0 && stuf[x-1].se.fi >= ord[y-1].se.fi)ans = max(ans, dp(x - 1, y, rem + stuf[x-1].fi) - stuf[x-1].se.se);
	//cerr << rem << " " << ord[y-1].fi << '\n';
	if(rem >= ord[y-1].fi)ans = max(ans, ord[y-1].se.se + dp(x, y - 1, rem - ord[y-1].fi));
	//cerr << x << " " << y << " " << rem << " " << ans << '\n';
	return memo[x][y][rem] = ans;
}

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<=n * 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, m, 0);
	//cout << dp(2, 2, 4) << '\n';
	//cout << dp(1, 2, 8) << '\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();
	}
}

컴파일 시 표준 에러 (stderr) 메시지

clo.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   53 | 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...