D. Take5

Codeforces
IDCF10100D
Time2000ms
Memory6MB
Difficulty
English · Original
Formal · Original
Pay attention to the *memory limit* for this problem! You are given an array A of size N and a positive integer S. You need to find the number of ways W in which you can chose 5 elements with distinct positions such that their sum is equal to S. The first line contains two positive integer N,  S (1 ≤ N ≤ 103,  0 ≤ S ≤ 2 * 109) - the size of the array and the queried sum. The next line contains N numbers Ai (0 ≤ Ai ≤ 4 * 108,  1 ≤ i ≤ N). Print the only integer W (0 ≤ W < 231) - the number of ways to chose the elements. ## Input The first line contains two positive integer N,  S (1 ≤ N ≤ 103,  0 ≤ S ≤ 2 * 109) - the size of the array and the queried sum. The next line contains N numbers Ai (0 ≤ Ai ≤ 4 * 108,  1 ≤ i ≤ N). ## Output Print the only integer W (0 ≤ W < 231) - the number of ways to chose the elements. [samples]
**Definitions** Let $ N \in \mathbb{Z}^+ $, $ S \in \mathbb{Z}_{\geq 0} $. Let $ A = (a_1, a_2, \dots, a_N) $ be a sequence of integers with $ a_i \in \mathbb{Z}_{\geq 0} $. **Constraints** 1. $ 1 \leq N \leq 10^3 $ 2. $ 0 \leq S \leq 2 \cdot 10^9 $ 3. $ 0 \leq a_i \leq 4 \cdot 10^8 $ for all $ i \in \{1, \dots, N\} $ **Objective** Compute the number of 5-element subsets $ \{i_1, i_2, i_3, i_4, i_5\} \subseteq \{1, \dots, N\} $ with $ i_1 < i_2 < i_3 < i_4 < i_5 $ such that: $$ a_{i_1} + a_{i_2} + a_{i_3} + a_{i_4} + a_{i_5} = S $$
API Response (JSON)
{
  "problem": {
    "name": "D. Take5",
    "description": {
      "content": "Pay attention to the *memory limit* for this problem! You are given an array A of size N and a positive integer S. You need to find the number of ways W in which you can chose 5 elements with distinc",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 6144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10100D"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Pay attention to the *memory limit* for this problem!\n\nYou are given an array A of size N and a positive integer S. You need to find the number of ways W in which you can chose 5 elements with distinc...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ N \\in \\mathbb{Z}^+ $, $ S \\in \\mathbb{Z}_{\\geq 0} $.  \nLet $ A = (a_1, a_2, \\dots, a_N) $ be a sequence of integers with $ a_i \\in \\mathbb{Z}_{\\geq 0} $.\n\n**Constraints**  \n1. ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments