华东师范大学 1045. 箱子打包 【贪心】
//华东师范大学 1045. 箱子打包 容易 #include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int MAXN = 1e5 + 10; int length[MAXN]; int main(){ int n,l; scanf("%d%d",&n,&l); for(int i=0;i<n;i++){ scanf("%d",&length[i]); } sort(length,length+n); int left = 0; int right = n-1; int answer = 0; while(left <= right){ if(length[left] + length[right] <= l){ left++; right--; }else{ right--; } answer++; } printf("%d",answer); return 0; }