3 Star 11 Fork 2

Shanire/OJCode

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
B3872.cpp 807 Bytes
一键复制 编辑 原始数据 按行查看 历史
Shanire 提交于 2023-11-16 15:05 +08:00 . Daily
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
struct Node
{
int t, r;
bool operator<(const Node &oth) const
{
if (r == oth.r)
{
return t < oth.t;
}
return r > oth.r;
}
};
Node ns[505];
set<int> s;
int main()
{
int n, ans = 0;
cin >> n;
for (int i = 1; i <= n; i++)
{
s.insert(i);
cin >> ns[i].t;
}
for (int i = 1; i <= n; i++)
{
cin >> ns[i].r;
}
sort(ns + 1, ns + 1 + n);
for (int i = 1; i <= n; i++)
{
auto it = s.upper_bound(ns[i].t);
if (it == s.begin()) // 没有更早的时间可以做这个游戏
{
continue;
}
ans += ns[i].r, s.erase(--it);
}
cout << ans << endl;
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/shanire/OJCode.git
git@gitee.com:shanire/OJCode.git
shanire
OJCode
OJCode
main

搜索帮助