小学数学C++

题目描述:

czk 老板开了个饮料连锁店,连锁店共有 n 家,出售的饮料种类相同。
为了促销,czk 决定让每家连锁店开展赠送活动。具体来说,在第 i 家店,顾客可以用 ai 个饮料瓶兑换到 bi 瓶饮料和 1 个纪念币(注意不足 ai 个饮料瓶则不能兑换,若 ai = 0  则表示不需要任何瓶子就可以兑换)。
一家店可以兑换多次,兑换得到的饮料瓶还可以继续用于兑换。你买了  s 瓶饮料,想知道用这 s 瓶饮料最多可以兑换到多少个纪念币。

输入样例:

3 11
4 1
5 2
8 4

输出样例:

3

AC代码 :

#include<bits/stdc++.h>
using namespace std;
inline unsigned long long read()
{
	unsigned long long f=1,x=0;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
struct node
{
	unsigned long long a;
	unsigned long long b;
	unsigned long long s;
}store[100086];
bool cmp(node x,node y)
{
	if(x.s==y.s)return x.a<y.a;
	return x.s<y.s;
}
int main()
{
	unsigned long long n,s;
	n=read();s=read();
	for (int i=1;i<=n;i++)
	{
		store[i].a=read();
		store[i].b=read();
		if(store[i].a<=store[i].b&&store[i].a<=s)
		{
			cout<<"-1";
			return 0;
		}
		store[i].s=store[i].a-store[i].b;
	}
	sort(store+1,store+1+n,cmp);
	
	long long num=0;
	for (int i=1;i<=n;i++)
	{
		if(s<store[i].a)continue;
		unsigned long long cnt=(s-store[i].a)/store[i].s+1;
		num+=cnt;
		s-=cnt*store[i].s;
	}
	cout<<num;
	return 0;
}

完结撒花

*★,°*:.☆( ̄▽ ̄)/$:*.°★* 。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值