Caisa and Sugar

本文介绍了一个有趣的买糖问题:主人公Caisa计划购买制作大巧克力蛋糕所需的原料,并打算前往镇上最大的超市购买糖。然而,他只有有限的资金且超市有着独特的找零政策——用糖果代替零钱找给顾客。本文探讨了如何在给定预算的情况下选择哪种类型的糖能获得最多的糖果。

Description

Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town.

Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are n types of sugar in the supermarket, maybe he able to buy one. But that's not all. The supermarket has very unusual exchange politics: instead of cents the sellers give sweets to a buyer as a change. Of course, the number of given sweets always doesn't exceed 99, because each seller maximizes the number of dollars in the change (100 cents can be replaced with a dollar).

Caisa wants to buy only one type of sugar, also he wants to maximize the number of sweets in the change. What is the maximum number of sweets he can get? Note, that Caisa doesn't want to minimize the cost of the sugar, he only wants to get maximum number of sweets as change.

Input

The first line contains two space-separated integers n, s(1 ≤ n, s ≤ 100).

The i-th of the next n lines contains two integers xi, yi(1 ≤ xi ≤ 100; 0 ≤ yi < 100), where xi represents the number of dollars and yi the number of cents needed in order to buy the i-th type of sugar.

Output

Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar.

Sample Input

Input
5 10
3 90
12 0
9 70
5 50
7 0
Output
50
Input
5 5
10 10
20 20
30 30
40 40
50 50
Output
-1

Hint

In the first test sample Caisa can buy the fourth type of sugar, in such a case he will take 50 sweets as a change.


#include<iostream>
using namespace std;

int main(){
    int n,money,x,y,maxsweets,tempsweets,flag;
    while(cin>>n>>money){
        flag=0;
        maxsweets=0;
        while(n--){
            cin>>x>>y;
            if(x<money){
                if(y==0){
                    tempsweets=0;
                }
                else{
                    tempsweets=100-y;
                }
                maxsweets=max(maxsweets,tempsweets);
                flag=1;
            }
            else if(x==money){
                if(y==0){
                    tempsweets=0;
                    maxsweets=max(maxsweets,tempsweets);
                    flag=1;
                }
            }
        }
        if(flag){
            cout<<maxsweets<<endl;
        }
        else{
            cout<<"-1"<<endl;
        }
    }
    return 0;
}


【2025年10月最新优化算法】混沌增强领导者黏菌算法(Matlab代码实现)内容概要:本文档介绍了2025年10月最新提出的混沌增强领导者黏菌算法(Matlab代码实现),属于智能优化算法领域的一项前沿研究。该算法结合混沌机制与黏菌优化算法,通过引入领导者策略提升搜索效率和全局寻优能力,适用于复杂工程优化问题的求解。文档不仅提供完整的Matlab实现代码,还涵盖了算法原理、性能验证及与其他优化算法的对比分析,体现了较强的科研复现性和应用拓展性。此外,文中列举了大量相关科研方向和技术应用场景,展示其在微电网调度、路径规划、图像处理、信号分析、电力系统优化等多个领域的广泛应用潜力。; 适合人群:具备一定编程基础和优化理论知识,从事科研工作的研究生、博士生及高校教师,尤其是关注智能优化算法及其在工程领域应用的研发人员;熟悉Matlab编程环境者更佳。; 使用场景及目标:①用于解决复杂的连续空间优化问题,如函数优化、参数辨识、工程设计等;②作为新型元启发式算法的学习与教学案例;③支持高水平论文复现与算法改进创新,推动在微电网、无人机路径规划、电力系统等实际系统中的集成应用; 其他说明:资源包含完整Matlab代码和复现指导,建议结合具体应用场景进行调试与拓展,鼓励在此基础上开展算法融合与性能优化研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值