[USACO12FEB]牛券Cow Coupons

本文讨论了USACO竞赛中的一道问题,FJ需要在预算M内购买N头奶牛,每头奶牛原价P_i,拥有K张优惠券可将价格降至C_i。目标是找出FJ最多能买多少头奶牛。输入包括奶牛数量、优惠券数量和预算,输出最大购买数。示例展示了当FJ有4头奶牛、1张优惠券和7单位预算时,通过优惠券购买策略,他可以买下3头奶牛。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目描述

Farmer John needs new cows! There are N cows for sale (1 <= N <= 50,000), and FJ has to spend no more than his budget of M units of money (1 <= M <= 10^14). Cow i costs P_i money (1 <= P_i <= 10^9), but FJ has K coupons (1 <= K <= N), and when he uses a coupon on cow i, the cow costs C_i instead (1 <= C_i <= P_i). FJ can only use one coupon per cow, of course.

What is the maximum number of cows FJ can afford?

FJ准备买一些新奶牛,市场上有N头奶牛(1<=N<=50000),第i头奶牛价格为Pi(1<=Pi<=109)。FJ有K张优惠券,使用优惠券购买第i头奶牛时价格会降为Ci(1<=Ci<=Pi),每头奶牛只能使用一次优惠券。FJ想知道花不超过M(1<=M<=1014)的钱最多可以买多少奶牛?
输入输出格式
输入格式:

  • Line 1: Three space-separated integers: N, K, and M.

  • Lines 2…N+1: Line i+1 contains two integers: P_i and C_i.

输出格式:

  • Line 1: A single integer, the maximum number of cows FJ can afford.

输入输出样例
输入样例#1: 复制

4 1 7
3 2
2 2
8 1
4 3

输出样例#1: 复制

3

说明

FJ has 4 cows, 1 coupon, and a budget of 7.

FJ uses the coupon on cow 3 and buys cows 1, 2, and 3, for a total cost of 3 + 2 + 1 = 6.

解法一:60分
用一个堆排序,并对用过的点打标记
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <cmath>
using namespace std;

int n,k,p,c,ans;
long long m;
bool bo[50005];
struct cyq{
   
   
    int mo,no;
    int pa;
}d;
priority_queue <cyq,vector<cyq>,greater<cyq> > q;
bool operator >(const cyq &aa,const cyq &bb){
   
   
    return aa.mo>bb.mo;
}

int main()
{
   
   
    scanf("%d%d%lld",&n,&k,&m);
    for(int i=1;i<=n;i++){
   
   scanf("%d%d",&p,&c);q.push((cyq){
   
   p,i,0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值