제출 #376129

#제출 시각아이디문제언어결과실행 시간메모리
376129YJUCloud Computing (CEOI18_clo)C++14
100 / 100
432 ms1644 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...