이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define int long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define inf 1000000009
#define MOD 1000000007
#define lim 200005
using namespace std;
int n,m;
vector<tuple<int, int, int>> vec; // frequence, core, value
int dp[4001][10001];
int calc(int cur, int cor){
if(cur>=n+m) return 0;
if(dp[cur][cor]!=-1) return dp[cur][cor];
if(cor >= (n+m-cur)*50){
if(get<1>(vec[cur]) > 0){
return dp[cur][cor] = calc(cur+1, cor);
}
else{
return dp[cur][cor] = calc(cur+1, cor + get<1>(vec[cur])) + get<2>(vec[cur]);
}
}
dp[cur][cor] = calc(cur+1, cor);
if(cor + get<1>(vec[cur]) >= 0) dp[cur][cor] = max(dp[cur][cor], calc(cur+1, cor + get<1>(vec[cur])) + get<2>(vec[cur]));
return dp[cur][cor];
}
void solve(){
cin >> n;
for(int i=1; i<=n; i++){
int c,f,v; cin >> c >> f >> v;
vec.pb({f, c, -v});
}
cin >> m;
for(int i=1; i<=m; i++){
int c,f,v; cin >> c >> f >> v;
vec.pb({f, -c, v});
}
for(int i=0; i<=n+m; i++) for(int j=0; j<=min(10000ll, (n+m)*50); j++) dp[i][j]=-1;
sort(all(vec), greater<tuple<int, int, int>>());
//for(auto i:vec) cerr << get<0>(i) spc get<1>(i) spc get<2>(i) << endl;
cout << max(calc(0, 0), 0ll) << endl;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
int t=1;
//cin >> t;
while(t--) solve();
}
# | 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... |