結果
| 問題 | 
                            No.2009 Drunkers' Contest
                             | 
                    
| コンテスト | |
| ユーザー | 
                             CuriousFairy315
                         | 
                    
| 提出日時 | 2022-07-15 22:20:35 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,270 ms / 2,000 ms | 
| コード長 | 1,268 bytes | 
| コンパイル時間 | 3,599 ms | 
| コンパイル使用メモリ | 91,220 KB | 
| 実行使用メモリ | 73,672 KB | 
| 最終ジャッジ日時 | 2024-06-27 18:47:05 | 
| 合計ジャッジ時間 | 50,774 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 54 | 
ソースコード
import static java.lang.System.err;
import static java.lang.System.out;
import java.util.ArrayDeque;
public class Main {
	public static void main(String[] args) {
		new Main();
		out.flush();
		err.flush();
	}
	static class Pair {
		double A, B;
		double min;
		double score;
		Pair(double A, double B) {
			this.A = A;
			this.B = B;
			min = Math.max(0, Math.sqrt(A / B) - 1);
			score = A / (min + 1) + B * (min + 1);
		}
		@Override
		public String toString() {
			return "(" + A + ", " + B + ", " + min + ", " + score + ")";
		}
	}
	/**
	 * @author 31536000(@CuriousFairy315)
	 */
	public Main() {
		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
			int N = sc.nextInt();
			long[] A = new long[N], B = new long[N];
			for (int i = 0;i < N;++ i) A[i] = sc.nextInt();
			for (int i = 0;i < N;++ i) B[i] = sc.nextInt();
			ArrayDeque<Pair> stack = new ArrayDeque<>();
			for (int i = N - 1;i >= 0;-- i) {
				Pair push = new Pair(A[i], B[i]);
				while (!stack.isEmpty() && stack.peekLast().min < push.min) {
					Pair pop = stack.pollLast();
					push = new Pair(push.A + pop.A, push.B + pop.B);
				}
				stack.add(push);
//				out.println(stack);
			}
			double ans = 0;
			for (Pair p : stack) ans += p.score;
			out.println(ans);
		}
	}
}
            
            
            
        
            
CuriousFairy315