题意:
贪心,排序后大数与小数相加
具体代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; #define maxn 100005 int n, m; int f[maxn]; int cmp(int a, int b) { return a > b; } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &f[i]); sort(f, f + n, cmp); int l = 0, r = n - 1; while (l <= r) { if (f[l] + f[r] <= m) r--; l++; } printf("%d ", l); return 0; }