이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define ckmin(a, b) a = min(a, b)
#define ckmax(a, b) a = max(a, b)
#define int long long
const int maxn = 1e5 + 5;
const ll INF = 1e18;
struct info{
int c, f, v, t;
info(){}
info(int _c, int _f, int _v, int _t) : c(_c), f(_f), v(_v), t(_t){}
bool operator < (const info& other) const{
return f < other.f || (f == other.f && t < other.t);
}
bool operator > (const info& other) const{
return f > other.f || (f == other.f && t > other.t);
}
};
signed main(void){
fastio;
int n;
cin>>n;
vector<info> a;
for(int i = 0; i < n; i++){
int c, f, v;
cin>>c>>f>>v;
a.pb(info(c, f, v, 1));
}
int m;
cin>>m;
for(int i = 0; i < m; i++){
int c, f, v;
cin>>c>>f>>v;
a.pb(info(c, f, v, -1));
}
sort(a.begin(), a.end(), greater<info>());
vector<int> dp(maxn + 1, -INF);
dp[0] = 0;
for(auto [c, f, v, t] : a){
if(t == 1){
for(int i = maxn - 1; i >= c; i--) dp[i] = max(dp[i], dp[i - c] - v);
}
else{
for(int i = 0; i < maxn - c; i++) dp[i] = max(dp[i], dp[i + c] + v);
}
}
int ans = 0;
for(int i = 0; i < maxn; i++) ans = max(ans, dp[i]);
cout<<ans<<"\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... |