• <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
            少妇久久久久久被弄高潮| 久久精品国产99国产电影网 | 久久久久久A亚洲欧洲AV冫| 久久久久久亚洲精品不卡 | 日韩精品久久久久久免费| 97久久天天综合色天天综合色hd | 久久精品中文无码资源站| 精品久久久久久久久午夜福利| 99久久99久久精品国产片果冻| 亚洲国产精品久久久天堂| 国产精品免费久久久久久久久| 亚洲国产另类久久久精品| 99久久精品国产一区二区蜜芽| 久久婷婷国产剧情内射白浆| 青青草原1769久久免费播放| 久久夜色精品国产噜噜亚洲AV| 久久丝袜精品中文字幕| 国内精品久久久久久野外| 精品伊人久久大线蕉色首页| 久久影视综合亚洲| 精品人妻伦一二三区久久 | 青春久久| 欧美激情精品久久久久久| 99久久国产免费福利| 精品一区二区久久| 国产精品一久久香蕉产线看 | 久久综合五月丁香久久激情| 99久久精品费精品国产| 热99re久久国超精品首页| 精品国产乱码久久久久久郑州公司| 国产成人久久精品一区二区三区| 久久精品免费大片国产大片| 99久久无码一区人妻| 成人亚洲欧美久久久久| 久久综合九色综合97_久久久| 狠狠久久亚洲欧美专区| 亚洲国产精久久久久久久| 99久久国产综合精品网成人影院| 久久久WWW成人| 久久中文字幕人妻丝袜| 午夜欧美精品久久久久久久|