# POJ 3663：Costume Party

Costume Party
 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12607 Accepted: 4977

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 N cows (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 6
3
5
2
1


Sample Output

4

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;

int num[20005];

int main()
{
int N,S,i,j;
scanf("%d%d",&N,&S);
int result=0;
for(i=1;i<=N;i++)
{
scanf("%d",&num[i]);
}

sort(num+1,num+N+1);

for(i=1;i<=N;i++)
{
for(j=1;j<i;j++)
{
if(num[i]+num[j]<=S)
{
result++;
}
else
{
break;
}
}
}

printf("%d\n",result);

return 0;
}

• 本文已收录于以下专栏：

## POJ 3663 Costume Party （二分查找）

Description It's Halloween! Farmer John is taking the cows to a costume party, but unfortunately he...

## poj3663 Costume Party

Costume Party Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11793   ...

## poj 3342 Party at Hali-Bula（树形DP+判断方式是不是唯一）

1、http://poj.org/problem?id=3342 2、题目大意： 现在要邀请n个人中的一些人参加晚宴，要求是有直接上下级关系的人不能同时出席，问最多可以邀请多少人参加，并判断在保证最大...

## POJ-Crazy tea party，很好的一道数学题~~~

Crazy tea party Time Limit: 1000MS   Memory Limit: 10000K        Descri...

## POJ-2342::Anniversary party-树形DP

Description There is going to be a party to celebrate the 80-th Anniversary of the Ural State Unive...

## POJ 3268 Silver Cow Party(Dijkstra)

POJ 3268 Silver Cow Party(Dijkstra) http://poj.org/problem?id=3268 题意:有N头牛要去参加牛X那里的聚会,现在除了X牛外,其他N-1头...

## 树形DP_____Party at Hali-Bula( POJ 3342 )

Description Dear Contestant, I'm going to have a party at my villa at Hali-Bula to celebrate my ...

## POJ 3268 D - Silver Cow Party(往返路程最短路)

举报原因： 您举报文章：POJ 3663：Costume Party 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)