이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |