結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 570 ms
32,328 KB
testcase_01 AC 718 ms
32,328 KB
testcase_02 AC 456 ms
32,284 KB
testcase_03 AC 470 ms
32,816 KB
testcase_04 AC 411 ms
32,768 KB
testcase_05 AC 140 ms
15,936 KB
testcase_06 WA -
testcase_07 AC 171 ms
16,192 KB
testcase_08 AC 194 ms
23,796 KB
testcase_09 AC 443 ms
26,280 KB
testcase_10 AC 193 ms
16,076 KB
testcase_11 WA -
testcase_12 AC 49 ms
12,480 KB
testcase_13 AC 635 ms
27,868 KB
testcase_14 AC 100 ms
16,248 KB
testcase_15 AC 32 ms
10,428 KB
testcase_16 AC 33 ms
10,464 KB
testcase_17 AC 33 ms
10,424 KB
testcase_18 AC 33 ms
10,444 KB
testcase_19 AC 33 ms
10,456 KB
testcase_20 AC 34 ms
10,500 KB
testcase_21 AC 35 ms
10,540 KB
testcase_22 AC 34 ms
10,528 KB
testcase_23 AC 33 ms
10,404 KB
testcase_24 AC 32 ms
10,476 KB
testcase_25 AC 33 ms
10,428 KB
testcase_26 AC 33 ms
10,576 KB
testcase_27 AC 34 ms
10,400 KB
testcase_28 AC 139 ms
24,368 KB
testcase_29 AC 96 ms
19,656 KB
testcase_30 AC 64 ms
16,396 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
    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