이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
const int N = 1e4 + 1;
const int inf = 1e15;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
vector <ar<int,4>> a;
for ( int i = 0; i < n; i++ ){
int c, f, v; cin >> c >> f >> v;
a.pb({f, 1, c, v});
}
int m; cin >> m;
for ( int i = 0; i < m; i++ ){
int c, f, v; cin >> c >> f >> v;
a.pb({f, 0, c, v});
}
sort(all(a));
reverse(all(a));
vector <int> dp(N, -inf);
dp[0] = 0;
for ( auto &[f, t, c, v]: a ){
if ( t == 0 ){ // customer
for ( int j = c; j < N; j++ ){
chmax(dp[j - c], dp[j] + v);
}
} else{
for ( int j = N - 1; j >= 0; j-- ){
chmax(dp[min(N - 1, j + c)], dp[j] - v);
}
}
}
cout << *max_element(all(dp));
cout << '\n';
}
# | 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... |