【51nod-1432】独木舟

 

排序后用二分,一直卡在最后一组数据,最后改成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\n", a.size()==1?sum+1:sum);
    return 0;
}
posted @ 2018-07-21 18:51  LesRoad  阅读(203)  评论(0编辑  收藏  举报