結果

問題 No.2567 A_1 > A_2 > ... > A_N
ユーザー H20
提出日時 2023-12-02 16:59:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,231 ms / 2,000 ms
コード長 733 bytes
コンパイル時間 1,049 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 90,492 KB
最終ジャッジ日時 2024-09-27 04:15:04
合計ジャッジ時間 8,610 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#めぐる式二分探索
#参考サイト:https://aotamasaki.hatenablog.com/entry/meguru_bisect

def is_ok(a):
    return N*(a+a-N+1)//2<=X

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

T = int(input())
for _ in range(T):
    N,X = map(int,input().split())
    XX = X
    M = meguru_bisect(10**19,0)
    L = list(range(M-N+1,M+1))[::-1]
    ANS = []
    i = 1
    while len(ANS)<N and X>=i:
        ANS.append(i)
        X-=i
        i+=1
    ANS[-1]+=X
    if len(ANS)==N:
        temp = XX-sum(L)
        for i in range(temp):
            L[i]+=1
        print(*L)
    else:
        print(-1)
0