| ||||||||||
| 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 | |||||||||
sos!一直TLE,不知道是我理解错了,还是什么```怎么想这题也不会是改TLE的题啊!!大牛们帮帮忙#include <stdio.h>
#include <algorithm>
short a[100000];
bool cmp(short &x,short &y)
{
return x>=y;
}
void main()
{
int n,max,min,mid,i,z;
short l;
scanf("%d %hd",&n,&l);
for(i=0;i<n;i++) scanf("%hd",&a[i]);
std::sort(a,a+n,cmp);
if(n%2!=0) min=(n>>1)+1;
else min=n>>1;
max=n;
while(min<=max)
{
mid=(max+min)>>1;
z=(mid<<1)-1;
for(i=mid;i<n;i++)
{
if((a[i]+a[z-i])>l)
{
min=mid+1;
goto next;
}
}
max=mid-1;
next: ;
}
max++;
printf("%d\n",max);
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator