提出 #73534538


ソースコード 拡げる

import sys
import string
import math
import bisect
import os
import heapq
import operator
from io import BytesIO, IOBase
from heapq import heappop,heappush
from functools import lru_cache,cache
from copy import copy,deepcopy
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,accumulate
from array import array


INF = float('inf')
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = sys.stdin.buffer.readline

ask = lambda *x:print('?',*x,flush=True)
reply = lambda *x:print('!',*x,flush=True)

RI = lambda: int(sys.stdin.readline())
RF = lambda: float(sys.stdin.readline())
RS = lambda: sys.stdin.readline().strip()
RFF = lambda: map(float, sys.stdin.readline().split())
RII = lambda: map(int, sys.stdin.readline().split())
RSS = lambda: map(str, sys.stdin.readline().strip().split())
RIL = lambda: list(RII())
RFL = lambda: list(RFF())
RSL = lambda: list(RSS())

from types import GeneratorType
def bootstrap(f, stack=[]):
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break 
                    to = stack[-1].send(to)
            return to

    return wrappedfunc


def main():
    test = RI()
    
    for _ in range(test):
        n,K,L = RII()
        a = RIL()
    
        b = []
        
        a.sort()
        l0 = a[0]
        r0 = a[-1]
        
        for i in range(n-1):
            b.append(a[i+1]-a[i])
        
        b.sort(reverse=True)
        ans = 0
        
        f = [0]*n
        for i in range(n-1):
            f[i] = f[i-1]+b[i]
        
        for i in range(min(n,K+1)):
            val = f[i-1]//2
            
            l = l0+val
            r = r0-val
            
            ans = max(ans,val+(max(l,L-r) if K>i else 0)+max(0,K-i-1)*(L-(r-l)))
        
        print(ans)
    
    



if __name__ == '__main__':
    main()

                

提出情報

提出日時
問題 A - Zombie
ユーザ x3x3
言語 Python (PyPy 3.11-v7.3.20)
得点 500
コード長 3909 Byte
結果 AC
実行時間 208 ms
メモリ 166284 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 1
AC × 22
セット名 テストケース
Sample 00_sample_01.txt
All 00_sample_01.txt, hand-12.txt, hand-13.txt, hand-14.txt, large-15.txt, large-16.txt, large-17.txt, random-01.txt, random-02.txt, random-03.txt, random-04.txt, random-05.txt, random-06.txt, random-07.txt, random-08.txt, random-09.txt, random-10.txt, random-11.txt, small-18.txt, small-19.txt, small-20.txt, small-21.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 116 ms 110496 KiB
hand-12.txt AC 116 ms 110596 KiB
hand-13.txt AC 143 ms 130948 KiB
hand-14.txt AC 145 ms 130612 KiB
large-15.txt AC 151 ms 163208 KiB
large-16.txt AC 196 ms 165772 KiB
large-17.txt AC 180 ms 130580 KiB
random-01.txt AC 208 ms 141948 KiB
random-02.txt AC 176 ms 117296 KiB
random-03.txt AC 170 ms 117020 KiB
random-04.txt AC 184 ms 130868 KiB
random-05.txt AC 191 ms 142644 KiB
random-06.txt AC 193 ms 139196 KiB
random-07.txt AC 199 ms 166284 KiB
random-08.txt AC 199 ms 165428 KiB
random-09.txt AC 202 ms 165276 KiB
random-10.txt AC 199 ms 165644 KiB
random-11.txt AC 202 ms 166008 KiB
small-18.txt AC 193 ms 164548 KiB
small-19.txt AC 174 ms 129136 KiB
small-20.txt AC 148 ms 156272 KiB
small-21.txt AC 144 ms 124920 KiB