7 条题解
-
1曾扬洋 (2022ts280) LV 9 @ 2023-5-2 18:18:43
#include<iostream> #include<algorithm> using namespace std; int n,m,a[1000005]; bool check(int h) { int sum = 0; for(int i = 1;i <= n;i++) if(a[i] > h) sum += (a[i]-h); return sum >= m; } int main() { cin >> n >> m; for(int i = 1;i <= n;i++) cin >> a[i]; int l = 0,r = 1000000000; while(l < r) { int mid = (l + r + 1) >> 1; if(check(mid)) l = mid; else r = mid - 1; } cout << l; return 0; }
-
02024-11-3 15:43:54@
#include<iostream> #include<algorithm> using namespace std; long long a[1000005]; long long n,m,ans; bool check(int x) { int sum = 0; for(int i = 1;i <= n;i++) { if(a[i] > x) sum += a[i] - x; } return sum >= m; } int main() { cin >> n >> m; for(int i = 1;i <= n;i++) { cin >> a[i]; } sort(a + 1,a + n + 1); long long l = 0,r = a[n]; while(l <= r) { int mid = (l + r) / 2; if(check(mid)) { ans = mid; l = mid + 1; } else r = mid - 1; } cout << ans << endl; return 0; }
-
02023-5-1 11:46:05@
#include<algorithm> using namespace std; int a[1000005],n,m; bool check(int h){ int sum=0; for (int i=1; i<=n; i++){ if (a[i]>h){ sum += (a[i]-h); } } return sum>=m; } int main(){ cin >>n >> m; for (int i=1; i<=n; i++){ cin >> a[i]; } int l=0,r=1000000000; while(l<r){ int mid=(l+r+1)>>1; if (check(mid)) { l=mid; } else { r=mid-1; } } cout << l; return 0; }
-
-12023-4-23 13:47:53@
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1000010; ll a[N]; ll n, m; ll check(ll x) { ll sum = 0; for (int i = 0; i < n; i++) { if (a[i] > x) { sum += (a[i] - x); if (sum >= m) return true; } } return false; } int main() { // freopen("in.txt", "r", stdin); cin >> n >> m; for (int i = 0; i < n; i++) scanf("%lld", a + i); ll l = 0, r = 0; for (int i = 0; i < n; i++) r = max(r, a[i]); //for (int i = l; i <= r; i++) cout << i << " " << check(i) << endl; while (l < r) { ll mid = l + r + 1 >> 1; if (check(mid)) l = mid; else r = mid - 1; } printf("%lld", l); return 0; }
-
-22024-11-3 15:46:04@
#include<iostream> #include<algorithm> using namespace std; int n,m,a[1114514]; bool check(int h) { int sum = 0; for(int i = 1;i <= n;i++) if(a[i] > h) sum += (a[i]-h); return sum >= m; } int main() { cin >> n >> m; for(int i = 1;i <= n;i++) cin >> a[i]; int l = 0,r = 1000000000; while(l < r) { int mid = (l + r + 1) >> 1; if(check(mid)) l = mid; else r = mid - 1; } cout << l; return 0; }
-
-22022-10-15 16:43:17@
cout << "293"
-
-42024-12-17 16:38:32@
#include<bits/stdc++.h> using namespace std; const int N=1e7+10; int sum,ans,num; int a[N],n,r; int main(){ cin>>n>>r; for(int i=1;i<=n;i++){ cin>>a[i]; } sort(a+1,a+n+1); num=n; while(sum<r){ sum+=(a[num]-a[num-1])*(n-num+1); num--; } num++; ans=a[num-1]+(sum-r)/(n-num+1); cout<<ans; return 0; } 小鸟
- 1
信息
- ID
- 1280
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 496
- 已通过
- 128
- 上传者