• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Uriel's Corner

            Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
            posts - 0, comments - 50, trackbacks - 0, articles - 594
            給定一個數列costs,一共k次操作,每次從前candidates和后candidates個數里面選較小的一個,問k次取到的k個數只和
            維護兩個優先隊列,一個存前candidates,一個存后candidates,注意每次pop之后要push后一個/前一個數


             1 #2462
             2 #Runtime: 1356 ms (Beats 44.93%)
             3 #Memory: 21.8 MB (Beats 68.12%)
             4 
             5 class Solution(object):
             6     def totalCost(self, costs, k, candidates):
             7         """
             8         :type costs: List[int]
             9         :type k: int
            10         :type candidates: int
            11         :rtype: int
            12         """
            13         left = costs[:candidates]
            14         right = costs[max(candidates, len(costs) - candidates):]
            15         heapify(left)
            16         heapify(right)
            17         ans = 0
            18         i = candidates
            19         j = len(costs) - candidates - 1
            20         for _ in range(k):
            21             if (not right) or (left and left[0] <= right[0]):
            22                 ans += heappop(left)
            23                 if i <= j:
            24                     heappush(left, costs[i])
            25                     i += 1
            26             else:
            27                 ans += heappop(right)
            28                 if i <= j:
            29                     heappush(right, costs[j])
            30                     j -= 1
            31         return ans
            亚洲AV无码久久精品蜜桃| 狠狠色婷婷综合天天久久丁香| 久久99精品久久久久久| 狠狠狠色丁香婷婷综合久久五月 | 伊人久久大香线蕉影院95| 久久综合久久久| 精品久久久久久久国产潘金莲| 久久久久久九九99精品| 久久久久国产精品三级网 | 97精品国产91久久久久久| 久久精品亚洲男人的天堂| 久久综合噜噜激激的五月天| 久久久久婷婷| 成人资源影音先锋久久资源网| 手机看片久久高清国产日韩| 久久亚洲国产中v天仙www| 久久综合鬼色88久久精品综合自在自线噜噜 | 久久国产亚洲精品麻豆| 一本色道久久综合| 久久精品成人一区二区三区| 久久精品www人人爽人人| 99久久做夜夜爱天天做精品| 日本一区精品久久久久影院| 亚洲精品无码久久久久去q | 国产99精品久久| 无码精品久久久久久人妻中字| 色偷偷88欧美精品久久久| 伊人久久综在合线亚洲2019| 日日噜噜夜夜狠狠久久丁香五月 | 日韩亚洲欧美久久久www综合网| 亚洲国产精品无码久久一线| 久久无码AV中文出轨人妻| 久久婷婷五月综合成人D啪| 国产成人精品久久| 99久久久国产精品免费无卡顿| 久久精品亚洲日本波多野结衣| 人妻精品久久久久中文字幕69 | 久久亚洲国产最新网站| 久久强奷乱码老熟女网站| 香蕉久久久久久狠狠色| 伊人久久大香线蕉成人|