Solution for CCC '16 S2 - Tandem Bicycle in C++


July 31, 2020 0.039250 seconds C++
#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;
}

Editorial


No editorial for this problem. :(

Original Problem


You can view the original page for this problem on the DMOJ.