我原本想的是如果选中两个和他们比赛,那么会产生两个并列的
但是此时仍然排名不变,因为在他前面的人数不变
因此题目更应该看重人数
AC代码:
#include <bits/stdc++.h>
using namespace std;
#define sf(x) scanf("%d", &x);
#define ll long long
#define Pu puts("");
#define de(x) cout << x << " ";
const int N = 5e5 + 10, M = 1e3 + 10;
struct E {
int u, id;
} s[N];
int n, m, ans;
bool cmp(E a, E b) {
return a.u < b.u;
}
int main() {
int T;
cin >> T;
while (T--) {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
sf(s[i].u);
s[i].id = i;
}
sort(s + 1, s + n + 1, cmp);
ans = 0;
for (int i = 1; i <= n; i++) {
if (s[i].u <= m) {
m -= s[i].u;
ans++;
}
}
int f = 0;
for (int i = 1; i <= ans; i++) {
if (s[i].id == ans + 1) {
f = 1;
break;
}
}
for (int i = ans + 1; i <= n; i++) {
if (s[i].id == ans + 1) {
if (m + s[ans].u >= s[i].u) {
f = 1;
break;
}
}
}
if (f)
ans++;
printf("%d\n", n - ans + 1);
}
}