Card Game

시간 제한3초메모리 제한2048 MB

요약
두 사람이 서로 다른 카드 두 장씩을 뽑아 두 합의 차가 정확히 C가 되는 경우의 수를 센다. 같은 숫자의 카드도 서로 다른 카드로 본다.
난이도

보통10점 중 6점

유형
해시맵, 조합론, 정렬, 투 포인터
정답자
아직 제출이 없습니다

문제

Vilius and Adomas play a simple card game. They have a deck of NN cards. Every card contains a number. Each player draws two random cards from the deck, adds the two numbers on the cards, and the player with the larger sum wins.

Vilius chose a number CC and wants to win by exactly CC points. In other words, he wants the sum of his cards minus the sum of Adomas's cards to be exactly CC. How many ways there are for Vilius and Adomas to draw their cards so that Vilius wins by exactly CC points?

The same number can be written on multiple cards. Then the case when a player draws one or another of them are considered distinct. The order of the two cards in a player's hand, however, does not matter. For example, if two cards contain the number 11 and three cards contain the number 22, there would be six ways for Adomas to draw cards with numbers 11 and 22.

입력

The first line contains two integers NN and CC (4≤N≤1,5004 \le N \le 1\\,500, 0≤C≤1090 \le C \le 10^9), the number of cards in the deck and the desired score difference, respectively. The second line contains NN integers A_1,A_2,…,A_NA\_1, A\_2, \ldots, A\_N (0≤A_i≤1090 \le A\_i \le 10^9), the numbers on the cards.

출력

Output a single integer: the number of ways the players can draw cards so that Vilius wins by exactly CC points.

예제2

  1. 예제 1

    입력
    5 3
    1 3 4 5 6
    
    예상 출력
    2
    
  2. 예제 2

    입력
    5 0
    2 2 2 2 2
    
    예상 출력
    30