Archived
23:26
This commit is contained in:
1 parent
bf08016dee
commit
8b21377d1f
1 file changed
+20
-10
+20
-10
@@ -3,17 +3,25 @@ using namespace std;
|
|||||||
int n;
|
int n;
|
||||||
long long m;
|
long long m;
|
||||||
long long a[500005];
|
long long a[500005];
|
||||||
long long check(long long now) {
|
long long qsum[500005];
|
||||||
int tot = lower_bound(a + 1, a + n + 1, now) - a - 1;
|
bool checkb(int mid, int now, int tot) {
|
||||||
// printf("%d\n", tot);
|
return mid * now - (qsum[tot] - qsum[tot - mid]) <= m;
|
||||||
|
}
|
||||||
|
long long check(long long now, int tot) {
|
||||||
long long nowm = m;
|
long long nowm = m;
|
||||||
long long ans = 0;
|
long long ans = 0;
|
||||||
while(a[tot + 1] == now && tot + 1 <= n) tot++;
|
int l = 1, r = tot, mid = (l + r) >> 1;
|
||||||
while(nowm >= (now - a[tot]) && tot >= 1) {
|
while(l < r) {
|
||||||
nowm -= now - a[tot], ans++, tot--;
|
mid = (l + r) >> 1;
|
||||||
// printf("%lld %d\n", nowm, tot);
|
if(checkb(mid, now, tot)) {
|
||||||
|
l = mid + 1;
|
||||||
|
} else {
|
||||||
|
r = mid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ans;
|
while(!checkb(mid, now, tot) && mid >= 1) mid--;
|
||||||
|
while(checkb(mid + 1, now, tot) && mid + 1 <= tot) mid++;
|
||||||
|
return mid;
|
||||||
}
|
}
|
||||||
int main() {
|
int main() {
|
||||||
freopen("crystal.in", "r", stdin);
|
freopen("crystal.in", "r", stdin);
|
||||||
@@ -21,12 +29,14 @@ int main() {
|
|||||||
scanf("%d%lld", &n, &m);
|
scanf("%d%lld", &n, &m);
|
||||||
for(int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
|
for(int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
|
||||||
sort(a + 1, a + n + 1);
|
sort(a + 1, a + n + 1);
|
||||||
|
for(int i = 1; i <= n; ++i) qsum[i] = qsum[i - 1] + a[i];
|
||||||
long long ans = 0;
|
long long ans = 0;
|
||||||
for(int i = 1; i <= n; ++i) {
|
for(int i = 1; i <= n; ++i) {
|
||||||
ans = max(ans, check(a[i]));
|
if(a[i + 1] == a[i]) continue;
|
||||||
|
ans = max(ans, check(a[i], i));
|
||||||
|
// printf("%d %lld\n", i, check(a[i], i));
|
||||||
}
|
}
|
||||||
printf("%lld\n", ans);
|
printf("%lld\n", ans);
|
||||||
// printf("%lld\n", check(4));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in new issue
Block a user