| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这么简单的题怎么问题这么多啊?吓死我了最一般的方法就可以啊,排序嘛,才79MS啊
#include<iostream>
#include<algorithm>
using namespace std;
int a[100005];
int main()
{
int n,len;
scanf("%d%d",&n,&len);
int i;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
int j=0;
int ans=0;
for(i=n-1;i>=0;i--)
{
if(i==j) {ans++;break;}
if(a[i]+a[j]<=len) j++;
ans++;
if(i==j) break;
}
printf("%d\n",ans);
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator