| ||||||||||
| 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 | |||||||||
二分查找函数水过#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,s,tot;
int a[20005];
int main()
{
cin>>n>>s;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+1+n);
for(int i=1;i<=n;i++)
{
int tmp=upper_bound(a+i,a+1+n,s-a[i])-a-1;
if(tmp>i)
tot+=tmp-i;
}
printf("%d\n",tot);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator