이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define LCBorz \
ios_base::sync_with_stdio(false); \
cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
#define x first
#define y second
const int N=100005;
const int INF=1e18;
struct qry{
int c,f,v;
bool operator<(const qry &o){
return f!=o.f?f>o.f:c>o.c;
}
};
int32_t main() {
LCBorz;
int n;cin>>n;
vector<qry> v;
for(int i=0;i<n;i++){
int a,b,c;cin>>a>>b>>c;
v.push_back({a,b,c});
}
int m;cin>>m;
for(int i=0;i<m;i++){
int a,b,c;cin>>a>>b>>c;
v.push_back({-a,b,c});
}
sort(all(v));
vector<int> dp(N,-INF);
dp[0]=0;
for(int i=0;i<n+m;i++){
auto [c,f,val]=v[i];
if(c>0){
for(int j=N-1;j>=c;j--){
dp[j]=max(dp[j],dp[j-c]-val);
}
}
else{
c=-c;
for(int j=0;j+c<N;j++){
dp[j]=max(dp[j],dp[j+c]+val);
}
}
}
int ans=0;
for(int i=0;i<N;i++){
ans=max(ans,dp[i]);
}
cout<<ans<<endl;
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... |