結果

問題 No.3166 [Cherry 7th Tune *] 桜の守人
ユーザー titia
提出日時 2025-06-05 01:35:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 458 ms / 2,000 ms
コード長 860 bytes
コンパイル時間 600 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 139,080 KB
最終ジャッジ日時 2025-06-05 01:35:26
合計ジャッジ時間 12,618 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from collections import Counter

T=int(input())
for tests in range(T):
    N,L,K=map(int,input().split())
    X=list(map(int,input().split()))

    OK=(L+1)//2
    NG=0

    while OK>NG+1:
        mid=(OK+NG)//2

        D=Counter()

        for x in X:
            l=x-mid
            r=x+mid

            if l<0:
                D[l%L]+=1
                l=0

            D[l]+=1

            if r>L:
                D[0]+=1
                r=r%L
            D[r]-=1

        if D[0]<K:
            NG=mid
            continue

        S=sorted(D)

        now=0
        flag=1
        for s in S:
            now+=D[s]

            if now<K:
                flag=0
                break

        #print(mid,flag,S,D)

        if flag:
            OK=mid
        else:
            NG=mid

    print(OK)

        

    
0