This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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... |