제출 #1119431

#제출 시각아이디문제언어결과실행 시간메모리
1119431ezzzayMoney (IZhO17_money)C++14
0 / 100
1 ms340 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...