思想
我们每次去枚举每个数打折扣的情况
code
#include <bits/stdc++.h>
#define int long long
using namespace std;
int N, B;
const int M = 1010;
int p[M], s[M], t[M];
int ans;
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> N >> B;
for (int i = 0; i < N; i++)
cin >> p[i] >> s[i];
//枚举每个优惠的方案
for (int i = 0; i < N; i++) {
t[i] = p[i] / 2 + s[i];
for (int j = 0; j < N; j++) {
if (i == j)continue;
else t[j] = p[j] + s[j];
}
sort(t, t + N);
for (int k = 0; k < N; k++) {
if (B < t[k]) {
ans = max(ans, k);
break;
} else {
B -= t[k];
}
}
}
cout << ans << endl;
return 0;
}