codeforces day 5

此博客介绍了如何解决一个关于鲨鱼吃罗非鱼的问题,其中涉及到了贪心算法和实现策略。鲨鱼有若干排牙齿,每排有不同的忍耐度,吃一只罗非鱼需要消耗一排牙齿。输入包括牙齿总数、牙齿排数及罗非鱼数量。通过计算每排牙齿中忍耐度最低的牙齿,得出最大能消耗的罗非鱼数量。程序实现了这一逻辑,并输出了最大可食用的罗非鱼数。
摘要由CSDN通过智能技术生成

problem tags:greedy,implementions

题目:有一只鲨鱼,它有几排牙齿,吃罗非鱼为生,吃一只罗非鱼用一排牙齿,每排牙齿都有忍耐度,当忍耐度不可为负数

input: the first lines is 3 integers n,m,k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) ,.--total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner.

Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c (0 ≤ c ≤ 106) — its residual viability.

output:

In the first line output the maximum amount of crucians that Valerie can consume for dinner.

#include <iostream>
#include<vector>
using  namespace std ;
int a[10001];
int main(int argc, const char * argv[])
{
   
    int n,m,k,r,c;
    int sum=0;
    cin>>n>>m>>k;
    memset(a, 10000, sizeof(a));
    for (int i=1; i<=n; i++)
    {
        cin>>r>>c;
        if (c<a[r])
        {
            a[r]=c;
        }
    }
    for (int i=1; i<=m; i++)
    {
       sum=sum+a[i];
    }
   if (sum>k)
    {
        sum=k;
    }
    cout<<sum;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值