1 条题解

  • 0
    @ 2025-10-8 17:01:39
    #include <bits/stdc++.h>
    using namespace std;
    using LL = long long;
    
    const int N = 5e4 + 10;
    struct node
    {
    	LL p, c;
    } a[N];
    bool cmp(node x, node y) { 
    	return (x.c != y.c) ? x.c < y.c : x.p < y.p; 
    }
    
    priority_queue<LL> q;
    
    int main()
    {
    	int n, k;
    	LL m;
    	scanf("%d%d%lld", &n, &k, &m);
    	for (int i = 1; i <= n; i++)
    		scanf("%lld%lld", &a[i].p, &a[i].c);
    	sort(a + 1, a + 1 + n, cmp);
    	LL sum = 0;
    	for (int i = 1; i <= n; i++)
    	{
    		if (i <= k)
    		{
    			sum += a[i].c;
    			q.push(a[i].p - a[i].c);
    		}
    		else
    		{
    			int x = q.top();
    			if (x + a[i].c < a[i].p)
    			{
    				sum += x + a[i].c;
    				q.pop();
    				q.push(a[i].p - a[i].c);
    			}
    			else
    				sum += a[i].p;
    		}
    		if (sum > m)
    		{
    			printf("%d\n", i - 1);
    			return 0;
    		}
    	}
    	printf("%d\n", n);
    	return 0;
    }
    
    
    • 1

    *【反悔贪心】奶牛优惠卷[USACO12FEB] Cow Coupons G

    信息

    ID
    2610
    时间
    1000ms
    内存
    128MiB
    难度
    8
    标签
    递交数
    229
    已通过
    34
    上传者