CodeForces Gym 100989G Mission in Amman (B)
来源:互联网 发布:华东师范大学知乎 编辑:程序博客网 时间:2024/06/01 16:55
答案满足单调性,所以二分答案去搞就行
#include <cstdio>#include <iostream>#include <algorithm>#include <cmath>#include <queue>#include <cstring>#include <vector>#include <set>using namespace std;#define ll long long#define maxn 100005ll num[maxn];ll M, K;ll work(ll tmp){ll sum = 0;for (int i = 0; i < M; ++i){if (num[i] > tmp)sum += num[i] - tmp;}return sum;}int main(){//freopen("input.txt", "r", stdin);//freopen("output.txt", "w", stdout);scanf("%I64d%I64d", &M, &K);for (int i = 0; i < M; ++i)scanf("%I64d", &num[i]);ll sum = 0, mx = 0;for (int i = 0; i < M; ++i){sum += num[i];if (num[i] > mx)mx = num[i];}ll x, y, m;x = sum / M;if (sum%M)++x;y = mx;while (x<y){m = (x + y) >> 1;if (work(m)<=K)y = m;elsex = m + 1;}ll ans = x;printf("%I64d\n", ans);//system("pause");//while (1);return 0;}
0 0
- CodeForces Gym 100989G Mission in Amman (B)
- CodeForces Gym 100989F Mission in Amman (A)
- GYM Amman 17 G. Super Subarray 暴力,最小公倍数.
- Codeforces Gym 2015 ACM Amman Collegiate Programming Contest
- CodeForces Gym 100989B LCS (B)
- codeforces gym 100548G
- CodeForces Gym 100735G
- CodeForces Gym 100735G
- Codeforces-GYM-100923G
- codeforces [Gym-100814G]
- Codeforces Gym-101617G
- codeforces gym 101142G Gangsters in Central City
- UESTC 2016 Summer Training #1 Div.2 F - Mission in Amman (A) 动态维护(刷新:--、++)
- CodeForces Gym 100114B
- CodeForces Gym 100735B
- Codeforces GYM 100726B
- Codeforces gym 101350G 数学
- Codeforces gym 101149 G 想法
- 数据库中如何求1-100以内的素数
- 团体程序设计天梯赛-练习集L2-003. 月饼
- Range Addition
- python 切片
- 21种工作流模式
- CodeForces Gym 100989G Mission in Amman (B)
- 有史来最大改变 Android 5.0十大新特性
- C#简单多线程Demo
- Property Animation
- hbase杂七杂八
- 属性动画高级用法之TypeEvaluator和Interpolator
- leetcode279. Perfect Squares
- Codeforces Round #316 (Div. 2) D DFS+vector+二分
- 记一次debug