没想到省选题居然考的是二分答案!
首先,我们可以发现, 和 其实没什么区别,假如我们把 看成 0 号牌,那么,相当于这 种牌中任意 种各一张可以组成一套牌。
然后, 种各一张可以转化为 种各拿一张再取回去一张。
#include <algorithm> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <list> #include <map> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define int long long #define I inline #define ri register int #define lowbit(x) x & -x #define For(i , x , y) for(ri i = x ; i <= y ; ++ i) #define Next(i , x) for(ri i = head[x] ; i ; i = e[i].nxt) I int read() { int s = 0 , w = 1; char ch = getchar(); while(ch < 48 || ch > 57) {if(ch == '-') w = -1; ch = getchar();} while(ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48) , ch = getchar(); return s * w; } const int N = 105; int n , m , a[N]; I bool judge(int mid) { int res = 0; For(i , 0 , n) res += max(0ll , mid - a[i]); return res <= mid; } signed main() { n = read() , a[0] = read(); For(i , 1 , n) a[i] = read(); int l = 0 , r = 1e10 , ans = 0; while(l <= r) { int mid = (l + r) >> 1; if(judge(mid)) ans = mid , l = mid + 1; else r = mid - 1; } cout << ans << endl; return 0; }
``