이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef pair<pi, ll> pl;
#define f first
#define s second
const int NN = 1e5+3;
int n, m;
ll dp[2][NN];
struct S{
int c;
int f;
ll v;
bool operator<(const S& y){
if(f == y.f)return c > y.c;
return f > y.f;
}
};
S trans[4003];
int main()
{
//setIO("");
cin >> n;
ll v;
for(int i=1, c, f;i<=n;i++){
cin >> c >> f >> v;
trans[i] = S{c, f, -v};
}
cin >> m;
for(int i=1, c, f;i<=m;i++){
cin >> c >> f >> v;
trans[n+i] = S{-c, f, v};
}
sort(trans+1, trans + n + m + 1);
for(int i=1;i<=50*m;i++){
dp[0][i] = dp[1][i] = -1e18;
}
for(int t=1;t<=n+m;t++){
int p = t % 2;
for(int i=0;i<=50*m;i++){
dp[p][i] = dp[1-p][i];
int ni = i - trans[t].c;
if(ni >= 0 && ni <= 50*m && dp[1-p][ni] != -1e18){
dp[p][i] = max(dp[p][i], dp[1-p][ni] + trans[t].v);
}
}
}
ll ans = 0;
for(int i=0;i<=50*m;i++){
ans = max(ans, dp[(n+m)%2][i]);
}
cout << ans << endl;
return 0;
}
# | 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... |