From bf08016dee210d518b187b7730a4f8f27ae47f24 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 31 Oct 2026 22:58:55 +0800 Subject: [PATCH] 22:58(45pts) --- crystal/crystal.cpp | 28 ++++++++++++++++++++++++---- hub/hub.cpp | 0 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 hub/hub.cpp diff --git a/crystal/crystal.cpp b/crystal/crystal.cpp index 7a0144f..346b7fd 100644 --- a/crystal/crystal.cpp +++ b/crystal/crystal.cpp @@ -2,15 +2,35 @@ using namespace std; int n; long long m; -int a[500005]; +long long a[500005]; +long long check(long long now) { + int tot = lower_bound(a + 1, a + n + 1, now) - a - 1; + // printf("%d\n", tot); + long long nowm = m; + long long ans = 0; + while(a[tot + 1] == now && tot + 1 <= n) tot++; + while(nowm >= (now - a[tot]) && tot >= 1) { + nowm -= now - a[tot], ans++, tot--; + // printf("%lld %d\n", nowm, tot); + } + return ans; +} int main() { freopen("crystal.in", "r", stdin); - freopen("crystal.out", "w", stdout); + // freopen("crystal.out", "w", stdout); scanf("%d%lld", &n, &m); - for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); - + for(int i = 1; i <= n; ++i) scanf("%lld", &a[i]); + sort(a + 1, a + n + 1); + long long ans = 0; + for(int i = 1; i <= n; ++i) { + ans = max(ans, check(a[i])); + } + printf("%lld\n", ans); + // printf("%lld\n", check(4)); return 0; } /* g++ crystal/crystal.cpp -o crystal/crystal -std=c++14 -O2 -static -Wall && cp crystal/crystal ~ && chmod +x ~/crystal && ~/crystal +O(n log n) +45pts */ \ No newline at end of file diff --git a/hub/hub.cpp b/hub/hub.cpp new file mode 100644 index 0000000..e69de29