Codeforces Round #570 (Div. 3) B. Equalize Prices、C. Computer Game、D. Candy Box (easy version)、E. Subsequences (easy version)
B题题意: 给你n个物品的价格,你需要找出来一个值b,使得每一个物品与这个b的差值的绝对值小于k。找到最大的b输出,如果找不到,那就输出-1 题解: 很简单嘛,找到上下限直接二分。下限就是所有物品中最小的价格。上限就是所有物品中最大价格加上k 代码: 1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 #include<map> 6 #include<math.h> 7 using namespace std; 8 typedef long long ll; 9 const int maxn=1e5+5; 10 const int mod=26; 11 const int INF=0x3f3f3f3f; 12 const int block=300; 13 int main() 14 { 15 int t; 16 scanf("%d",&t); 17 while(t--) 18 { 19 int b,n,k,minn=INF,maxx=0; 20 scanf("%d%d",&n,&k); 21 for(int i=1;i<=n;++i) 22 { 23 scanf("%d",&b); 24 minn=min(minn,b); 25 maxx=max(maxx,b)