正文
增加 34 行删除 65 行
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475```cpp/*** @file main.cpp* @author [Your Name]* @brief [Problem Name] - [OJ Link]* @date 2026-11-07*/#include <bits/stdc++.h>using namespace std;// ==================== 类型别名 ====================using ll = long long;using ull = unsigned long long;using pii = pair<int, int>;using pll = pair<ll, ll>;using vi = vector<int>;using vll = vector<ll>;// ==================== 常量 ====================constexpr int INF = 0x3f3f3f3f;constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL;constexpr int MOD = 1e9 + 7;constexpr double EPS = 1e-9;// ==================== 宏 ====================#define all(x) (x).begin(), (x).end()#define rall(x) (x).rbegin(), (x).rend()#define pb push_back#define eb emplace_back#define fi first#define se second#define sz(x) (int)(x).size()// ==================== 快速 IO ====================inline void fast_io() {ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}// ==================== 常用函数 ====================template <typename T>inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template <typename T>inline T lcm(T a, T b) { return a / gcd(a, b) * b; }template <typename T>inline T qpow(T a, ll b, T mod = MOD) {T res = 1;a %= mod;while (b) {if (b & 1) res = res * a % mod;a = a * a % mod;b >>= 1;}return res;}// ==================== 主函数 ====================void solve() {// 在此编写题解逻辑}int main() {fast_io();int t = 1;cin >> t; // 多组数据时取消注释while (t--) {solve();}return 0;}```1234567891011121314151617181920212223242526272829303132333435363738394041424344```cpp#include <bits/stdc++.h>#define int long longusing namespace std;const int MAXN = 5e5 + 5;int n, a[MAXN], m;int s[MAXN];bool check (int len) {for(int l = 1; l <= n - len + 1; l++){int r = l + len - 1;int sum = s[r] - s[l - 1];int nw = a[r] * len;int cost = nw - sum;if (cost <= m) return true;}return false;}signed main() {ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);cin >> n >> m;for (int i = 1; i <= n; i++) {cin >> a[i];}sort (a + 1, a + 1 + n);for (int i = 1; i <= n; i++) {s[i] = s[i-1] + a[i];}int l = 1, r = n, ans = 0;while (l <= r) {int mid = (l + r) / 2;if (check(mid)) {l = mid + 1;ans = mid;}else {r = mid - 1;}}cout << ans;return 0;}```