题目描述:
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;
}
完结撒花
*★,°*:.☆( ̄▽ ̄)/$:*.°★* 。