이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int MAX = 1e5 + 5;
struct t{
ll c, f, p, op;
bool operator <(const t & x){
if(f == x.f) return p < x.p;
return f > x.f;
}
};
ll n, m, c, f, p, dp[MAX];
vector<t> v;
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
while(n--){
cin >> c >> f >> p;
v.push_back({c, f, -p, 0LL});
}
cin >> m;
while(m--){
cin >> c >> f >> p;
v.push_back({c, f, p, 1LL});
}
sort(all(v));
memset(dp, 0xc1, sizeof(dp));
dp[0] = 0;
for(auto& x : v){
if(x.p < 0){
for(int i = MAX - 1; i >= x.c; i--)
dp[i] = max(dp[i], dp[i - x.c] + x.p);
}
else{
for(int i = 0; i + x.c < MAX; i++)
dp[i] = max(dp[i], dp[i + x.c] + x.p);
}
}
ll ans = 0;
for(int i = 0; i < MAX; i++) ans = max(ans, dp[i]);
cout << ans;
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... |