• <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
            2021久久国自产拍精品| 久久久无码精品午夜| 99精品国产综合久久久久五月天| 国内精品久久久久久久久| 美女久久久久久| 亚洲综合日韩久久成人AV| 激情伊人五月天久久综合| 国产成人精品综合久久久| 婷婷久久综合九色综合绿巨人 | 亚洲精品无码成人片久久| 久久99国内精品自在现线| 久久精品国产一区二区电影| 欧美大香线蕉线伊人久久| 狠狠色综合网站久久久久久久| 精品国产日韩久久亚洲| 久久国产精品99精品国产987| 亚洲国产日韩欧美久久| 久久se精品一区精品二区| 久久久无码精品亚洲日韩京东传媒 | 人妻无码久久精品| 久久噜噜电影你懂的| 亚洲愉拍99热成人精品热久久 | 奇米影视7777久久精品人人爽| 国产亚洲色婷婷久久99精品| 亚洲AV伊人久久青青草原| 久久久久波多野结衣高潮| 久久www免费人成看片| 国产99久久久国产精品~~牛| 五月丁香综合激情六月久久| 精品久久久久久国产牛牛app | 久久久久国产精品麻豆AR影院| 久久w5ww成w人免费| 国产色综合久久无码有码| 久久人妻AV中文字幕| 亚洲国产成人精品女人久久久| 色综合久久综精品| 久久久青草久久久青草| 四虎国产永久免费久久| 超级碰久久免费公开视频| 久久青青草原精品影院| 91精品国产高清久久久久久国产嫩草 |