NEKO_Daze @ 2024-02-04 17:06:35
合着这升级了但没完全升级是吧喵(无语
#include <bits/stdc++.h>
using namespace std;
struct Apple {
int x, y;
}p;
struct cmp{
bool operator()(Apple a, Apple b)
{
return a.y > b.y;
}
};
priority_queue <Apple, vector<Apple>, cmp> q;
int s, a, b, n, ans, h;
int main()
{
cin >> n >> s;
cin >> a >> b;
h = a + b;
for (int i = 1; i <= n; i++)
{
cin >> p.x >> p.y;
q.push(p);
}
while (!q.empty() && s >= 0)
{
if (q.top().x <= h && q.top().y <= s)
{
ans++;
s -= q.top().y;
}
q.pop();
}
cout << ans;
return 0;
}
by tasimei @ 2024-02-04 17:13:37
@NEKO_Daze 不是你知道 堆
是几级知识点吗……别乱叫啊
by NEKO_Daze @ 2024-02-04 17:14:26
@zhanghaowei111 ???要用堆吗?
by tasimei @ 2024-02-04 17:15:55
@NEKO_Daze 不是,你这 priority_queue
不是堆,是什么?
by BGM114514 @ 2024-02-04 17:21:04
也就您能想到用priority_queue做这题啦(bushi
by NEKO_Daze @ 2024-02-04 18:01:17
@zhanghaowei111 优先队列啊?
by Lan_yan @ 2024-02-04 19:00:57
@NEKO_Daze 不是涉及优先队列的题是入门?
by gghack_Nythix @ 2024-02-05 08:06:13
@NEKO_Daze 优先队列是堆把
by yiwugougou @ 2024-04-03 21:08:52
这不是一道普通贪心题吗?咋还有队列啊!