이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
# define int long long
# define fir first
# define sec second
# define pb push_back
# define endl "\n"
const int cnst = 1e4+5;
bool mutipletestcase = 0;
//bool debug = false;
// bool sorting(tuple<int, int, int, bool> a, tuple<int, int, int, bool> b) {
// auto[a1, a2, a3, a4] = a;
// auto[b1, b2, b3, b4] = b;
// return a1 < b1;
// }
void solve() {
int n; cin >> n;
vector<tuple<int, int, int, bool>> vec;
for(int i = 1; i<=n; i++) {
int a, b, c; cin >> a >> b >> c;
vec.pb({b, a, c, 0});
}
int m; cin >> m;
for(int i = 1; i<=m; i++) {
int a, b, c; cin >> a >> b >> c;
vec.pb({b, a, c, 1});
}
sort(vec.begin(), vec.end());
reverse(vec.begin(), vec.end());
int dp[cnst]; dp[0] = 0;
for(int i = 1; i<=1e4; i++) dp[i] = 1e18*-1;
for(auto [pow, fre, cos, id]: vec) {
if(!id) {
for(int i = 1e4; i>=fre; i--) dp[i] = max(dp[i], dp[i-fre]-cos);
}
else {
for(int i = 0; i<=1e4-fre; i++) dp[i] = max(dp[i], dp[i+fre]+cos);
}
// for(int i = 1; i<=10; i++) cerr << dp[i] << " "; cerr << endl;
}
int ans = 0;
for(int i = 0; i<=1e4; i++) ans = max(ans, dp[i]);
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int t = 1;
if(mutipletestcase) 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... |