結果

問題 No.750 Frac #1
ユーザー Grenache
提出日時 2019-04-26 16:23:24
言語 Java
(openjdk 23)
結果
AC  
実行時間 141 ms / 1,000 ms
コード長 1,019 bytes
コンパイル時間 5,097 ms
コンパイル使用メモリ 79,816 KB
実行使用メモリ 41,880 KB
最終ジャッジ日時 2024-11-24 14:17:56
合計ジャッジ時間 10,966 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder750 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		List<Integer> nu = new ArrayList<>(n);
		List<Integer> de = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			nu.add(a);
			de.add(b);
			for (int j = nu.size() - 1; j > 0; j--) {
				int pa = nu.get(j - 1);
				int pb = de.get(j - 1);
				if (pa * b < a * pb) {
					Collections.swap(nu, j, j - 1);
					Collections.swap(de, j, j - 1);
				} else {
					break;
				}
			}
		}

		for (int i = 0; i < n; i++) {
			pr.printf("%d %d%n", nu.get(i), de.get(i));
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}
0