結果

問題 No.110 しましまピラミッド
ユーザー koyumeishikoyumeishi
提出日時 2014-12-23 23:35:51
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 832 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 78,736 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-31 11:00:55
合計ジャッジ時間 2,058 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int func(vector<int> w, vector<int> b){
	int cnt = 0;
	int i=0, j=0;
	int last = 1e9;
	while(1){
		if(cnt%2==0){
			if(i>=w.size()) break;
			if(last > w[i]){
				last = w[i];
				cnt++;
			}
			i++;
		}else{
			if(j>=b.size()) break;
			if(last > b[j]){
				last = b[j];
				cnt++;
			}
			j++;
		}
	}
	
	return cnt;
}

int main(){
	int N;
	cin >> N;
	vector<int> w(N);
	for(int i=0; i<N; i++) cin >> w[i];
	sort(w.begin(), w.end(), greater<int>());
	
	int M;
	cin >> M;
	vector<int> b(M);
	for(int i=0; i<M; i++) cin >> b[i];
	sort(b.begin(), b.end(), greater<int>());

	int ans = max( func(w,b), func(b,w) );
	cout << ans << endl;
	return 0;
}
0