이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x) cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define ull unsigned long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ld long double
#define nl endl
#define tb '\t'
#define sp ' '
#define sqr(x) (x)*(x)
#define arr3 array<ll, 3>
using namespace std;
const ll MX=2005, MOD=1000000007, BLOCK=160, INF=2e9+7, LG=62;
const ll INFF=1000000000000000007;
const ld ERR=1e-6, pi=3.14159265358979323846;
ll N, DP[2][50*MX];
vector<arr3> A;
int main(){
fastio;
cin >> N;
for(ll i=0, c, f, v; i<N; i++){
cin >> c >> f >> v;
A.pb({f, c, -v});
}
cin >> N;
for(ll i=0, c, f, v; i<N; i++){
cin >> c >> f >> v;
A.pb({f, -c, v});
}
N=A.size();
A.pb({INF, INF, INF});
sort(all(A), greater<arr3>());
for(int j=1; j<=100000; j++)
DP[0][j]=-INFF;
DP[0][0]=0;
for(int i=1, now, bef; i<=N; i++){
now=i%2, bef=now^1;
for(int j=0; j<=50; j++){
DP[now][j]=DP[bef][j];
if(j-A[i][1]>=0 && j-A[i][1]<=50 && DP[bef][j-A[i][1]]!=INFF){
DP[now][j]=max(DP[now][j], DP[bef][j-A[i][1]]+A[i][2]);
}
}
}
N%=2;
for(int i=1; i<=50; i++)
DP[N][0]=max(DP[N][0], DP[N][i]);
cout << DP[N][0] << nl;
}
# | 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... |