結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 623 ms
33,576 KB
testcase_01 AC 783 ms
33,552 KB
testcase_02 AC 506 ms
33,592 KB
testcase_03 AC 496 ms
32,260 KB
testcase_04 AC 431 ms
32,332 KB
testcase_05 AC 154 ms
16,068 KB
testcase_06 WA -
testcase_07 AC 185 ms
16,132 KB
testcase_08 AC 204 ms
24,104 KB
testcase_09 AC 487 ms
26,248 KB
testcase_10 AC 211 ms
16,172 KB
testcase_11 WA -
testcase_12 AC 51 ms
12,544 KB
testcase_13 AC 673 ms
27,820 KB
testcase_14 AC 105 ms
16,148 KB
testcase_15 AC 35 ms
10,360 KB
testcase_16 AC 34 ms
10,468 KB
testcase_17 AC 35 ms
10,476 KB
testcase_18 AC 35 ms
10,484 KB
testcase_19 AC 34 ms
10,516 KB
testcase_20 AC 35 ms
10,516 KB
testcase_21 AC 37 ms
10,404 KB
testcase_22 AC 37 ms
10,528 KB
testcase_23 AC 35 ms
10,404 KB
testcase_24 AC 35 ms
10,552 KB
testcase_25 AC 35 ms
10,424 KB
testcase_26 AC 35 ms
10,364 KB
testcase_27 AC 34 ms
10,304 KB
testcase_28 AC 146 ms
24,424 KB
testcase_29 AC 101 ms
19,692 KB
testcase_30 AC 67 ms
16,600 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
print(ans)
0