제출 #1276044

#제출 시각아이디문제언어결과실행 시간메모리
1276044WH8Cloud Computing (CEOI18_clo)C++20
100 / 100
266 ms1452 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long 
#define pll pair<int, int>
#define mp make_pair
#define pb push_back
#define f first
#define s second

const int maxc=100005;

signed main(){
	int s;cin>>s;
	vector<tuple<int,int,int,int>> v;
	// clock,num,price,type;
	for(int i=0;i<s;i++){
		int clock,num,price,type=0;
		cin>>num>>clock>>price;
		v.pb({clock,type, num,price});
	}
	int q;cin>>q;
	for(int i=0;i<q;i++){
		int clock,num,price,type=1;
		cin>>num>>clock>>price;
		v.pb({clock,type,num,price});
	}
	sort(v.begin(),v.end(), [&](auto a, auto b){
			if(get<0>(a) == get<0>(b)){
				return get<1>(a) < get<1>(b);
			}
			return get<0>(a) > get<0>(b);
		});
	int n=v.size(), ans=0;
	vector<int> prof(100005, -1e15);
	prof[0]=0;
	for(int i=0;i<n;i++){
		auto [clock,type,num,price]=v[i];
		//~ printf("%lld %lld %lld %lld considering\n", clock,num,price,type);
		if(type==0){
			for(int j=maxc-1;j>=0;j--){
				
				int from=j-num;
				if(from >= 0){
					prof[j]=max(prof[from]-price, prof[j]);
				}
			}
		}
		else {
			for(int j=0;j<maxc;j++){
				int from=j+num;
				if(from < maxc){
					prof[j]=max(prof[from]+price, prof[j]);
				}
			}
		}
	}
	for(int i=0;i<maxc;i++){
		ans=max(ans, prof[i]);
	}
	cout<<ans;
}		
#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...