結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 568 ms
33,636 KB
testcase_01 AC 732 ms
33,596 KB
testcase_02 AC 466 ms
33,488 KB
testcase_03 AC 497 ms
32,480 KB
testcase_04 AC 440 ms
32,684 KB
testcase_05 AC 148 ms
15,868 KB
testcase_06 WA -
testcase_07 AC 180 ms
16,096 KB
testcase_08 AC 195 ms
24,128 KB
testcase_09 AC 460 ms
26,292 KB
testcase_10 AC 200 ms
16,048 KB
testcase_11 WA -
testcase_12 AC 49 ms
12,456 KB
testcase_13 AC 644 ms
27,736 KB
testcase_14 AC 102 ms
16,376 KB
testcase_15 AC 33 ms
10,460 KB
testcase_16 AC 34 ms
10,364 KB
testcase_17 AC 34 ms
10,520 KB
testcase_18 AC 34 ms
10,480 KB
testcase_19 AC 33 ms
10,512 KB
testcase_20 AC 34 ms
10,452 KB
testcase_21 AC 35 ms
10,516 KB
testcase_22 AC 35 ms
10,500 KB
testcase_23 AC 33 ms
10,416 KB
testcase_24 AC 33 ms
10,320 KB
testcase_25 AC 33 ms
10,412 KB
testcase_26 AC 33 ms
10,448 KB
testcase_27 AC 33 ms
10,416 KB
testcase_28 AC 138 ms
24,400 KB
testcase_29 AC 96 ms
19,712 KB
testcase_30 AC 64 ms
16,616 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
        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
print(ans)
0