排序后用二分,一直卡在最后一组数据,最后改成long long才AC...
#include <bits/stdc++.h> using namespace std; typedef long long LL; vector<LL> a; int main() { LL n, m, sum = 0, x; cin>>n>>m; for(LL i=0; i<n; i++) { scanf("%lld", &x); a.push_back(x); } sort(a.begin(), a.end()); while(a.size() > 1) { LL x = a.back(); LL s = m-x; a.erase(a.end()-1); LL k = upper_bound(a.begin(), a.end(), s)-a.begin(); if(a[k-1]<=s) { a.erase(a.begin()+k-1); sum++; } else sum++; } printf("%lld ", a.size()==1?sum+1:sum); return 0; }