結果

問題 No.2028 Even Choice
ユーザー vwxyzvwxyz
提出日時 2022-09-22 03:01:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,331 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 11,012 KB
実行使用メモリ 33,584 KB
最終ジャッジ日時 2023-08-23 20:21:06
合計ジャッジ時間 6,721 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 432 ms
33,584 KB
testcase_01 AC 535 ms
33,556 KB
testcase_02 AC 377 ms
33,524 KB
testcase_03 AC 448 ms
32,528 KB
testcase_04 AC 396 ms
32,532 KB
testcase_05 AC 112 ms
15,904 KB
testcase_06 WA -
testcase_07 AC 130 ms
16,212 KB
testcase_08 AC 170 ms
24,128 KB
testcase_09 AC 332 ms
26,256 KB
testcase_10 AC 141 ms
16,092 KB
testcase_11 WA -
testcase_12 AC 46 ms
12,456 KB
testcase_13 AC 442 ms
27,676 KB
testcase_14 AC 91 ms
16,248 KB
testcase_15 AC 33 ms
10,440 KB
testcase_16 AC 32 ms
10,420 KB
testcase_17 AC 35 ms
10,424 KB
testcase_18 AC 33 ms
10,552 KB
testcase_19 AC 34 ms
10,368 KB
testcase_20 AC 33 ms
10,536 KB
testcase_21 AC 33 ms
10,528 KB
testcase_22 AC 33 ms
10,520 KB
testcase_23 AC 33 ms
10,380 KB
testcase_24 AC 32 ms
10,324 KB
testcase_25 AC 32 ms
10,412 KB
testcase_26 AC 36 ms
10,412 KB
testcase_27 AC 32 ms
10,364 KB
testcase_28 AC 133 ms
24,448 KB
testcase_29 AC 93 ms
19,708 KB
testcase_30 AC 62 ms
16,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
import time
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
from math import gcd as GCD
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines
write=sys.stdout.write

N,K=map(int,readline().split())
A=list(map(int,readline().split()))
A1=[(A[i],-i) for i in range(1,N,2)]
_heapify_max(A1)
ans=0
min_i=N
queue=[]
while K and A1:
    a,i=_heappop_max(A1)
    i=-i
    while K and queue and queue[0]>=a:
        ans+=queue[0]
        _heappop_max(queue)
        K-=1
    if K==0:
        break
    if i<min_i:
        for j in range(i+1,min_i,2):
            _heappush_max(queue,A[j])
        min_i=i
    if K:
        ans+=a
        K-=1
    while K and queue and queue[0]>=a:
        ans+=queue[0]
        _heappop_max(queue)
        K-=1
while K:
    ans+=queue[0]
    _heappop_max(queue)
    K-=1
print(ans)
0