이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
using namespace std;
vector<ll> stuff[4001];
ll dp[2][100001];
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
ll n;
cin >> n;
ll cur = 0;
FOR(i,0,n){
ll c,f,v;
cin >> c >> f >> v;
stuff[cur] = {-f, -v, c};
cur++;
}
ll m;
cin >> m;
FOR(i,0,m){
ll c,f,v;
cin >> c >> f >> v;
stuff[cur] = {-f, v, c};
cur++;
}
sort(stuff, stuff+n+m);
FOR(i,0,2){
FOR(j,0,100001) dp[i][j] = -1000000000000000000;
}
dp[0][0] = 0;
FOR(i,0,n+m){
FOR(j,0,100001){
if (stuff[i][1]<0){
if (j+stuff[i][2] <= 100000 ) dp[1][j+stuff[i][2]] = max(dp[1][j+stuff[i][2]], dp[0][j] + stuff[i][1]);
}else{
if (j-stuff[i][2]>=0 ) dp[1][j-stuff[i][2]] = max(dp[1][j-stuff[i][2]] , dp[0][j] + stuff[i][1]);
}
dp[1][j] = max(dp[1][j], dp[0][j]);
}
FOR(j,0,100001) dp[0][j] = dp[1][j], dp[1][j] = -1000000000000000000;
}
ll maxi = 0;
FOR(i,0,100001){
maxi = max(maxi, dp[0][i]);
}
cout << maxi << endl;
}
# | 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... |