이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define ar array<int, 4>
bool ckmin(int& a, int b){return b < a ? a = b, 1 : 0;}
bool ckmax(int& a, int b){return b > a ? a = b, 1 : 0;}
const int N = 2e3 + 5, mod = 1e9 + 7;
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0);
int n; cin >> n;
vector<array<int, 4>> v(4005);
for(int i = 0; i < n; i++) cin >> v[i][1] >> v[i][0] >> v[i][2], v[i][3] = 1;
int m; cin >> m;
for(int i = n; i < n + m; i++) cin >> v[i][1] >> v[i][0] >> v[i][2], v[i][3] = 0;
sort(v.begin(), v.begin() + n + m, [&](ar a, ar b) {if(a[0] == b[0]) return a[3] > b[3]; return a[0] > b[0];});
vector<int> dp(1e5 + 5, -1e18);
dp[0] = 0;
for(int i = 0; i < n + m; i++) {
vector<int> next = dp;
if(v[i][3]) for(int j = v[i][1]; j <= 1e5; j++) next[j] = max(next[j], dp[j - v[i][1]] - v[i][2]);
else for(int j = 0; j <= 1e5 - v[i][1]; j++) next[j] = max(next[j], dp[j + v[i][1]] + v[i][2]);
dp = next;
}
int ans = 0;
for(int i = 0; i <= 1e5; i++) ans = max(ans, dp[i]);
cout << ans << 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... |