結果

問題 No.2028 Even Choice
ユーザー vwxyzvwxyz
提出日時 2022-09-22 02:12:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,249 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 11,048 KB
実行使用メモリ 32,820 KB
最終ジャッジ日時 2023-08-23 20:19:15
合計ジャッジ時間 8,619 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 588 ms
32,420 KB
testcase_01 AC 748 ms
32,216 KB
testcase_02 AC 466 ms
32,372 KB
testcase_03 AC 487 ms
32,772 KB
testcase_04 AC 421 ms
32,820 KB
testcase_05 AC 146 ms
15,856 KB
testcase_06 WA -
testcase_07 AC 181 ms
16,092 KB
testcase_08 AC 204 ms
23,700 KB
testcase_09 AC 460 ms
26,240 KB
testcase_10 AC 203 ms
16,012 KB
testcase_11 WA -
testcase_12 AC 51 ms
12,480 KB
testcase_13 AC 648 ms
27,608 KB
testcase_14 AC 103 ms
16,212 KB
testcase_15 AC 34 ms
10,436 KB
testcase_16 AC 34 ms
10,400 KB
testcase_17 AC 33 ms
10,448 KB
testcase_18 AC 33 ms
10,448 KB
testcase_19 AC 35 ms
10,488 KB
testcase_20 AC 34 ms
10,612 KB
testcase_21 AC 34 ms
10,468 KB
testcase_22 AC 34 ms
10,480 KB
testcase_23 AC 34 ms
10,408 KB
testcase_24 AC 33 ms
10,396 KB
testcase_25 AC 33 ms
10,472 KB
testcase_26 AC 34 ms
10,404 KB
testcase_27 AC 33 ms
10,356 KB
testcase_28 AC 136 ms
24,376 KB
testcase_29 AC 95 ms
19,696 KB
testcase_30 AC 64 ms
16,428 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-1
queue=[]
while K and A1:
    a,i=_heappop_max(A1)
    i=-i
    if i<min_i:
        for j in range(i+1,min_i+1,2):
            _heappush_max(queue,A[j])
        min_i=i
        ans+=a
        K-=1
    else:
        _heappush_max(queue,a)
    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
assert K==0
print(ans)
0