题目链接:codeforces.com/problemset/problem/1183/B


题意:给你 n 个数,每个数能在k范围内上下浮动,求能否使所有数相等,能输出相等的最大值,不能输出 -1.

思路: 因为要求最大,所以将所有数向上浮动k,找到他们的最大最小值,如果相差不超过2*k,最小值即为答案。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--)
{
int n;
int k;
int a;
cin >> n >> k;
cin >> a;
int mi = a + k,ma = a + k;
for(int i = ;i < n;i++)
{
cin >> a;
if(mi > a + k) mi = a + k;
if(ma < a + k) ma = a + k;
}
if(ma - mi <= *k) cout << mi << endl;
else cout << - << endl;
}
return ;
}

Codeforcs 1183B Equalize Prices的更多相关文章

  1. CF1234A Equalize Prices

    洛谷 CF1234A Equalize Prices Again 洛谷传送门 题目描述 You are both a shop keeper and a shop assistant at a sma ...

  2. Codeforces Round #590 (Div. 3) A. Equalize Prices Again

    链接: https://codeforces.com/contest/1234/problem/A 题意: You are both a shop keeper and a shop assistan ...

  3. Codeforces Round #570 (Div. 3) B. Equalize Prices

    原文链接https://codeforces.com/contest/1183/problem/B 题意:进行Q组测试,在每组中有长度为n的数组a[i],然后现在给你一个K,问你找到一个bi使得|ai ...

  4. 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 题解: 很简单嘛,找到上下限直接二分.下限就是所有物品中最 ...

  5. Eqaulize Prices

    There are n products in the shop. The price of the ii-th product is aiai. The owner of the shop want ...

  6. Codeforces Round #590 (Div. 3)

    A. Equalize Prices Again 题目链接:https://codeforces.com/contest/1234/problem/A 题意:给你 n 个数 , 你需要改变这些数使得这 ...

  7. Codeforces Round #590 (Div. 3)(e、f待补

    https://codeforces.com/contest/1234/problem/A A. Equalize Prices Again #include<bits/stdc++.h> ...

  8. Round #590 (Div. 3)

    拿DIV找快乐... 当场过了A-B1-B2-C 写D差5分钟写的是正解...留坑补FG A. Equalize Prices Again 直接判断sum%n==0?sum/n:sum/n+1 B1, ...

  9. Codeforces Round #590

    题目链接:Round #590 题目答案:官方Editorial.My Solution A. Equalize Prices Again 签到题还WA了一发,向上取整有点问题: //my wrong ...

随机推荐

  1. (59)C# IIS Express 设置

    支持非localhost访问 本地测试时 修改 localhost改成127.0.0.1

  2. python主要探索函数

    在数据分析中,Python的主要探索函数 Python中主要用于书探索的是pandas(数据分析)和matplotlib(数据可视化).其中pandas提供了大量的数据探索的工具与数据相关的函数,这些 ...

  3. vim 更改注释颜色

    在 ~/.vimrc 添加命令: highlight Comment ctermfg=green

  4. 用scp实现多服务器文件分发

    需要安装expect环境 yum install expect -y vi ip.txt #主机地址池 192.168.1.1 192.168.1.2 192.168.3.3 #如果是同一网段也可以不 ...

  5. The document cannot be opened. It has been renamed, deleted or moved.

    In the Individual components section of the Visual Studio Installer, make sure that Razor Language S ...

  6. Codeforces 388C Fox and Card Game (贪心博弈)

    Codeforces Round #228 (Div. 1) 题目链接:C. Fox and Card Game Fox Ciel is playing a card game with her fr ...

  7. Cai_Sublime

    Cai_Sublime Package Control:插件包管理工具 The simplest method of installation is through the Sublime Text ...

  8. Hooks初探

    一.创建自己的HOOkS,并进行封装 二.创建自己的HOOkS,并进行封装

  9. TypeScript和JavaScript的区别

    JavaScript和TypeScript的对比 注:参考https://juejin.im/entry/5a52ed336fb9a01cbd586f9f做的笔记 概要介绍 JavaScript Ja ...

  10. adb 提示adb server version(31) doesn't match this client(40) 解决办法

    有时候我们用adb工具去连接安卓设备,或者模拟器的时候,会提示adb server version(31) doesn't match this client(40)这样的提示.如图 提示的字面意思就 ...