이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define ve vector
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
using namespace std;
mt19937 rnd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
struct cpu{
int c;
ll f, v;
};
const int MAXN = 4048;
const int MAXC = 51*MAXN;
ll dp[2][MAXC];
cpu a[2*MAXN];
inline bool comp(const cpu& c1, const cpu& c2){
if(c1.f == c2.f)
return c1.c > c2.c;
return c1.f > c2.f;
}
void solve(){
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i].c >> a[i].f >> a[i].v;
a[i].v *= -1;
}
int m;
cin >> m;
for(int i = n + 1; i <= n + m; i++){
cin >> a[i].c >> a[i].f >> a[i].v;
a[i].c *= -1;
}
sort(a + 1, a + m + n + 1, comp);
fill(dp[0], dp[0] + MAXC, -1e18);
fill(dp[1], dp[1] + MAXC, -1e18);
dp[0][0] = 0;
for(int i = 1; i <= n + m; i++){
int cur = i & 1;
int prev = cur ^ 1;
for(int j = 0; j < i*51; j++){
dp[cur][j] = dp[prev][j];
if(j - a[i].c >= 0 && j - a[i].c < MAXC)
dp[cur][j] = max(dp[cur][j], dp[prev][j - a[i].c] + a[i].v);
}
}
cout << *max_element(dp[(n + m) & 1], dp[(n + m) & 1] + MAXC);
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
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... |