POJ Costume Party

来源:互联网 发布:上海银行mac控件下载 编辑:程序博客网 时间:2024/04/29 08:01

Description

It's Halloween! Farmer John is taking the cows to a costume party, but unfortunately he only has one costume. The costume fits precisely two cows with a length of (1 ≤ S ≤ 1,000,000). FJ has Ncows (2 ≤ N ≤ 20,000) conveniently numbered 1..N; cow i has length Li (1 ≤ Li ≤ 1,000,000). Two cows can fit into the costume if the sum of their lengths is no greater than the length of the costume. FJ wants to know how many pairs of two distinct cows will fit into the costume.

Input

* Line 1: Two space-separated integers: N and S
* Lines 2..N+1: Line i+1 contains a single integer: Li

Output

* Line 1: A single integer representing the number of pairs of cows FJ can choose. Note that the order of the two cows does not matter.

Sample Input

4 63521

Sample Output

4

题解

翻译看百度,水题。

#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<iostream>#include<algorithm>using namespace std;int n,m,ans,a[20001];int main(){scanf("%d%d",&n,&m);for(int i=1;i<=n;i++)   scanf("%d",&a[i]);sort(a+1,a+n+1);for(int i=1;i<n;i++)   {if(a[i]+a[i+1]>=m) break;    for(int j=i+1;j<=n;j++)           {if(a[i]+a[j]<=m)       ans++;else break;   }   }printf("%d\n",ans);return 0;}



0 0