Nathan Coulas

CCC '16 S2 - Tandem Bicycle

ccc16s2 CPP11 31 Jul, 2020 0.039s 5 points

Source Code

#include <bits/stdc++.h>
using namespace std;

typedef long long LL; 
typedef pair<int, int> pii; 
typedef pair<LL, LL> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<LL> vl; 
typedef vector<vl> vvl;
typedef queue<int> qi;
typedef queue<char> qc;
typedef stack<int> si;
typedef stack<char> sc;


int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	bool type;
	int n;
	cin >> n; 
	type = n - 1;
	cin >> n;
	
	int PEG[n];
	int DMOJ[n];
	
	for(int i = 0; i < n; i++){
		cin >> DMOJ[i];
	}
	
	for(int i = 0; i < n; i++){
		cin >> PEG[i];
	}
	
	sort(DMOJ, DMOJ + sizeof(DMOJ)/sizeof(DMOJ[0]));
	sort(PEG, PEG + sizeof(PEG)/sizeof(PEG[0]));
	
	int total = 0;
	int j = n - 1;
	for(int i = 0; i < n; i++, j--){
		if(type){//Type 2
			total += max(PEG[j], DMOJ[i]);
		}else{
			total += max(PEG[j], DMOJ[j]);
		}	 
	}
	cout << total << "\n";

	return 0;
}