AcWing
  • 首页
  • 活动
  • 题库
  • 竞赛
  • 应用
  • 更多
    • 题解
    • 分享
    • 商店
    • 问答
    • 吐槽
  • App
  • 登录/注册

AcWing 2025. 奶牛优惠卷

作者: 作者的头像   炽热的 ,  2022-06-11 16:23:45 ,  所有人可见 ,  阅读 68


2


#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int, pair<int, int>> PII;

const int N = 50010;

int n, k;
LL m;
bool st[N];

int main()
{
    cin.tie(0)->sync_with_stdio(false);

    priority_queue<PII, vector<PII>, greater<PII>> heap;
    cin >> n >> k >> m;

    for (int i = 1; i <= n; i ++ )
    {
        int a, b;
        cin >> a >> b;
        heap.push({a, {1, i}});
        heap.push({b, {2, i}});
    }

    LL res = 0;
    while (heap.size() && m > 0)
    {
        auto t = heap.top();
        heap.pop();
        LL w = t.x; int p = t.y.x, id = t.y.y;
        if (m < w) break;
        if (st[id] || (k == 0 && p == 2)) continue;
        st[id] = true;
        m -= w, res ++ ;
        if (p == 2) k -- ;
    }

    cout << res << endl;

    return 0;
}

0 评论

你确定删除吗?

© 2018-2023 AcWing 版权所有  |  京ICP备17053197号-1
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息