gym-101343F-Abdalrahman Ali Bugs

 1 /*
 2 证书可以每次批量买a个,现在需要x个,问至少要买多少个。
 3 把所有a排序,然后对于每个x二分搜索不小于x的最小的a,然后输出即可。
 4 */
 5 #include <bits/stdc++.h>
 6 using namespace std;
 7 const int maxn=1e5+5;
 8 int n,a[maxn],m,x;
 9 int main()
10 {
11     cin>>n;
12     for(int i=0;i<n;i++)
13         cin>>a[i];
14     sort(a,a+n);
15     int m;
16     cin>>m;
17     for(int i=0;i<m;i++)
18     {
19         cin>>x;
20         int l=0,r=n-1;
21         while(l<=r)
22         {
23             int mid=l+(r-l)/2;
24             if(a[mid]<x)
25                 l=mid+1;
26             else
27                 r=mid-1;
28         }
29         if(a[l]>=x)
30             cout<<a[l]<<endl;
31         else
32             cout<<"Dr. Samer cannot take any offer :(."<<endl;
33     }
34 }

 

转载于:https://www.cnblogs.com/kearon/p/7214831.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值