UVA 1149 水题

来源:互联网 发布:编写软件程序步骤 编辑:程序博客网 时间:2024/06/05 17:18
#include <bits/stdc++.h>using namespace std;const int maxn = 1E5 + 10;int n, l, cnt, T, L[maxn];int main(int argc, char const *argv[]){cin >> T;while (T--){cin >> n >> l;for (int i = 0; i < n; i++)cin >> L[i];sort(L, L + n, greater<int>());cnt = 0;for (int i = 0, j = n - 1; i < n && j >= i; i++){cnt++;if (L[j] + L[i] <= l)j--;}cout << cnt << endl;if (T) cout << endl;}return 0;}


排序,最大和最小相加,超过容器,则不相加,改加次大的,以此类推

0 0
原创粉丝点击