結果

問題 No.110 しましまピラミッド
ユーザー kenji_shioya
提出日時 2016-06-25 21:29:36
言語 Java
(openjdk 23)
結果
AC  
実行時間 142 ms / 5,000 ms
コード長 973 bytes
コンパイル時間 4,001 ms
コンパイル使用メモリ 77,988 KB
実行使用メモリ 54,400 KB
最終ジャッジ日時 2024-12-31 11:23:12
合計ジャッジ時間 8,747 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Exercise127{
  public static void main (String[] args){

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] w = new int[n];
    for(int i = 0; i < n; i++){
      w[i] = sc.nextInt();
    }
    Arrays.sort(w);
    n = sc.nextInt();
    int[] b = new int[n];
    for(int i = 0; i < n; i++){
      b[i] = sc.nextInt();
    }
    Arrays.sort(b);
    System.out.println(Math.max(build(w, b), build(b, w)));
	}
  private static int build(int[] first, int[] second){
    int top = first[first.length - 1];
    int count = 1;
    boolean f = true;
    for(int i = second.length - 1; i >= 0; i--){
      if(second[i] < top && f){
        top = second[i];
        count++;
        f = false;
        for(int j = first.length - 1; j >=0; j--){
          if(first[j] < top){
            top = first[j];
            count++;
            f = true;
            break;
          }
        }
      }
    }
    return count;
  }
}
0