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
5 10 3 90 12 0 9 70 5 50 7 0
50
5 5 10 10 20 20 30 30 40 40 50 50
-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;
}
本文介绍了一个有趣的买糖问题:主人公Caisa计划购买制作大巧克力蛋糕所需的原料,并打算前往镇上最大的超市购买糖。然而,他只有有限的资金且超市有着独特的找零政策——用糖果代替零钱找给顾客。本文探讨了如何在给定预算的情况下选择哪种类型的糖能获得最多的糖果。
968

被折叠的 条评论
为什么被折叠?



