結果

問題 No.3165 [Cherry 7th Tune A] Croissants Continu
ユーザー LyricalMaestro
提出日時 2025-06-21 13:43:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 600 ms / 2,000 ms
コード長 1,536 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 82,184 KB
実行使用メモリ 127,532 KB
最終ジャッジ日時 2025-06-21 13:43:29
合計ジャッジ時間 10,636 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/3165


def solve2(N, A, X):
    f_index = 0
    first = True
    for a in A:
        index = f_index
        if first:
            x = X // 2 + (1 if X % 2 == 1 else 0)
            x -= f_index // 2
            a0 = min(a, x)
            index += 2 * a0
            if index >= X:
                index = 1
                first = False
                a -= a0
                if f_index <= 2:
                    f_index = index
                    continue

                a0 = min(a, (f_index - 3) // 2 + 1)
                index += 2 * a0
                if index >= X:
                    break
                f_index = index
                continue
            else:
                f_index = index
        else:
            index += 2 * a
            if index >= X:
                break
            f_index = index
            continue
    
    return index >= X



def solve(N, A):
    total_a = sum(A)
    A.sort(reverse=True)

    low = 0
    high = total_a
    while high - low > 1:
        mid = (high + low) // 2
        if solve2(N, A, mid):
            low = mid
        else:
            high = mid
    if solve2(N, A, high):
        return high
    else:
        return low


def main():
    T = int(input())
    answers = []
    for _ in range(T):
        N = int(input())
        A = list(map(int, input().split()))
        ans = solve(N, A)
        answers.append(ans)

    for ans in answers:
        print(ans)




        





    



if __name__ == "__main__":
    main()
0