이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector,Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll N=1e5+5;
const ll MOD=1e9+7;
const ll INF=(1LL<<61);
const ld pi=acos(-1);
#define REP(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
struct ob{
ll c,f,val,type;
};
vector<ob>a;
ll n,dp[N],m;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n;
REP(i,n){
ob tmp;
cin>>tmp.c>>tmp.f>>tmp.val;
tmp.type=0;
a.pb(tmp);
}
cin>>m;
REP(i,m){
ob tmp;
cin>>tmp.c>>tmp.f>>tmp.val;
tmp.type=1;
a.pb(tmp);
}
sort(a.begin(),a.end(),[](ob A,ob B){
if(A.f!=B.f)return A.f>B.f;
return (A.type<B.type);
});
REP(i,N)dp[i]=-INF;
dp[0]=0;
for(auto t:a){
if(t.type==0){
for(int i=N-1;i>=0;i--){
if(i+t.c<N)dp[i+t.c]=max(dp[i+t.c],dp[i]-t.val);
}
}else{
for(int i=0;i<N;i++){
if(i-t.c>=0)dp[i-t.c]=max(dp[i-t.c],dp[i]+t.val);
}
}
}
ll ans=0;
REP(i,N)ans=max(ans,dp[i]);
cout<<ans<<"\n";
return 0;
}
/*
7 1
5 0
5 0
7 0
3 0
4 0
4 3 0
2 1 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... |