当前位置: 首页> 科技> 互联网 > 专卖二手手表网站_川畅互联咨询 网站建设_品牌推广内容_网站建设开发公司

专卖二手手表网站_川畅互联咨询 网站建设_品牌推广内容_网站建设开发公司

时间:2025/7/9 13:38:30来源:https://blog.csdn.net/2402_88149600/article/details/146165930 浏览次数:1次
专卖二手手表网站_川畅互联咨询 网站建设_品牌推广内容_网站建设开发公司

P1109 学生分组 - 洛谷

代码区:

#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int locate[2];
int arry[55];
int cmp(const int& a, const int& b) {return a>b;
}
int main() {int n,add=0,sub=0,count=0,sum=0;cin >> n;for (int i = 0; i < n; i++) {cin >> arry[i];sum += arry[i];}for (int i = 0; i < 2; i++) {cin >> locate[i];}//sort(arry, arry+n,cmp);if (sum<locate[0] * n || sum>locate[1] * n) {cout << -1;return 0;}for (int i = 0; i < n; i++) {if (arry[i] < locate[0]) {//在下界左边,需要增加add+= locate[0] - arry[i];}else if (arry[i] > locate[1]) {//在下界右边需要减少sub+= arry[i] - locate[1];}}count = max(add, sub);cout << count;}

欢迎各位读者提出意见。

(菜菜奋斗小日记)

关键字:专卖二手手表网站_川畅互联咨询 网站建设_品牌推广内容_网站建设开发公司

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: