이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int n, m;
int limits[MAXN];
bool canDistribute(int x) {
long long needed = 0;
// Calculate total coins needed to give at least x coins to each person
for (int i = 0; i < n; i++) {
// Give min(x, limit) coins to each person
int give = min(x, limits[i]);
needed += give;
}
// Check if total needed coins is less than or equal to available coins
return needed <= m;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// Read input
cin >> n >> m;
// Read individual coin limits
for (int i = 0; i < n; i++) {
cin >> limits[i];
}
// Binary search for maximum minimum distribution
int left = 0, right = 1e9;
int best = 0;
while (left <= right) {
int mid = left + (right - left) / 2;
if (canDistribute(mid)) {
best = mid;
left = mid + 1;
} else {
right = mid - 1;
}
}
// Output the result
cout << best << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |