详见:https://leetcode.com/problems/ipo/description/

C++:

class Solution {
public:
int findMaximizedCapital(int k, int W, vector<int>& Profits, vector<int>& Capital)
{
vector<pair<int, int>> v;
for (int i = 0; i < Capital.size(); ++i)
{
v.push_back({Capital[i], Profits[i]});
}
sort(v.begin(), v.end());
for (int i = 0; i < k; ++i)
{
int left = 0, right = v.size(), mx = 0, idx = 0;
while (left < right)
{
int mid = left + (right - left) / 2;
if (v[mid].first <= W)
{
left = mid + 1;
}
else
{
right = mid;
}
}
for (int j = right - 1; j >= 0; --j)
{
if (mx < v[j].second)
{
mx = v[j].second;
idx = j;
}
}
W += mx;
v.erase(v.begin() + idx);
}
return W;
}
};

参考:http://www.cnblogs.com/grandyang/p/6788811.html

502 IPO 上市的更多相关文章

  1. [LeetCode] 502. IPO 上市

    Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Cap ...

  2. Java实现 LeetCode 502 IPO(LeetCode:我疯起来连自己都卖)

    502. IPO 假设 力扣(LeetCode)即将开始其 IPO.为了以更高的价格将股票卖给风险投资公司,力扣 希望在 IPO 之前开展一些项目以增加其资本. 由于资源有限,它只能在 IPO 之前完 ...

  3. [LeetCode] IPO 上市

    Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Cap ...

  4. [LeetCode解题报告] 502. IPO

    题目描述 假设 LeetCode 即将开始其 IPO.为了以更高的价格将股票卖给风险投资公司,LeetCode希望在 IPO 之前开展一些项目以增加其资本. 由于资源有限,它只能在 IPO 之前完成最 ...

  5. 从B站、爱奇艺、映客的IPO上市,看国内视频公司的内容审核现状

    本文由  网易云发布. 3月30日,中央电视台<经济半小时>栏目讲述了网络上的一个顽症——色情内容.在这期主题为<互联网上的“色诱”>的节目中,央视的记者揭示了色情直播的猖獗. ...

  6. 【LeetCode】502. IPO

    题目 假设 LeetCode 即将开始其 IPO.为了以更高的价格将股票卖给风险投资公司,LeetCode希望在 IPO 之前开展一些项目以增加其资本. 由于资源有限,它只能在 IPO 之前完成最多 ...

  7. 502. IPO

    Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Cap ...

  8. Leetcode 502.IPO

    IPO 假设 LeetCode 即将开始其 IPO.为了以更高的价格将股票卖给风险投资公司,LeetCode希望在 IPO 之前开展一些项目以增加其资本. 由于资源有限,它只能在 IPO 之前完成最多 ...

  9. 第九周 Leetcode 502. IPO (HARD)

    Leetcode 502 一个公司 目前有资产W 可以选择实现K个项目,每个项目要求公司当前有一定的资产,且每个项目可以使公司的总资产增加一个非负数. 项目数50000 设计一个优先队列,对于当前状态 ...

随机推荐

  1. CentOS笔记-vim

    详细的参考http://www.runoob.com/linux/linux-vim.html i插入 I 行首插入 A 行尾插入 fn + ←,行首 fn + →,行尾 fn + ↑,向上翻页 fn ...

  2. SpringMVC中返回JSON时乱码的解决方案

    springMVC中返回JSON会出现乱码,解决如下: produces = "text/html;charset=UTF-8" @ResponseBody @RequestMap ...

  3. Java WebSocket库:https://github.com/TooTallNate/Java-WebSocket

    https://github.com/TooTallNate/Java-WebSocket 以下是简单示例: import com.google.gson.JsonObject; import com ...

  4. js中字符串函数indexOf与search的区别

    IndexOf()方法是用来判断一个字符串是否存在于一个更长的字符串中.从长字符串左端到右端来搜索,如果存在该子字符串就返回它所处的位置(即索引).如果在被搜索的字符串没有找到要查找的字符串返回-1. ...

  5. extjs4 treepanel 多个checkbox先中 多个节点选中 多级节点展开

    //<%@ page contentType="text/html; charset=utf-8" %> var checkedNodes = { _data:{}, ...

  6. sql server filter table name

    https://stackoverflow.com/questions/26577464/how-to-find-a-table-in-sql-server-if-only-the-partial-t ...

  7. html5--6-3 CSS语法2

    html5--6-3 CSS语法2 实例 div包含p和h标签的时候可以,但是p标签包含h标签的时候不可以  学习要点 掌握引入外部样式表方法 插入样式的三种方法 内联样式表(行内) 内部样式表(st ...

  8. 推箱子 hdu1254

    推箱子 1  http://acm.hdu.edu.cn/showproblem.php?pid=1254 推箱子 2  http://acm.hzau.edu.cn/problem.php?id=1 ...

  9. codeforces 459E E. Pashmak and Graph(dp+sort)

    题目链接: E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input st ...

  10. RxJava 参考文档

    /*************************************************************** * RxJava 参考文档 * 说明: * 最近无意中发现RxJava ...