C. Large Summation

Codeforces
IDCF10153C
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
You are given an array a consisting of n element a1, a2, ..., an. For each element ai you must find another element aj (i ≠ j), such that the summation of ai and aj mod (109 + 7) (i.e. (ai + aj) % (109 + 7)) is as maximal as possible. Can you help judges by solving this hard problem? The first line contains an integer T, where T is the number of test cases. The first line of each test contains an integer n (2 ≤ n ≤ 105), where n is the size of the array a. The second line of each test case contains n integers a1, a2, ..., an (0 ≤ ai < 109 + 7), giving the array a. For each test case, print a single line containing n space separated elements, such that the ith element is the answer to the ith element in the array a (i.e. the maximum value of (ai + aj) % (109 + 7)). As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use _scanf/printf_ instead of _cin/cout_ in C++, prefer to use _BufferedReader/PrintWriter_ instead of _Scanner/System.out_ in Java. ## Input The first line contains an integer T, where T is the number of test cases.The first line of each test contains an integer n (2 ≤ n ≤ 105), where n is the size of the array a.The second line of each test case contains n integers a1, a2, ..., an (0 ≤ ai < 109 + 7), giving the array a. ## Output For each test case, print a single line containing n space separated elements, such that the ith element is the answer to the ith element in the array a (i.e. the maximum value of (ai + aj) % (109 + 7)). [samples] ## Note As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use _scanf/printf_ instead of _cin/cout_ in C++, prefer to use _BufferedReader/PrintWriter_ instead of _Scanner/System.out_ in Java.
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case $ k \in \{1, \dots, T\} $: - Let $ n_k \in \mathbb{Z} $ denote the size of the array, with $ 2 \leq n_k \leq 10^5 $. - Let $ A_k = (a_{k,1}, a_{k,2}, \dots, a_{k,n_k}) $ be a sequence of integers where $ 0 \leq a_{k,i} < 10^9 + 7 $. Let $ M = 10^9 + 7 $. **Constraints** 1. $ 1 \leq T \leq \text{large} $ (implied by constraints on $ n $) 2. For each $ k \in \{1, \dots, T\} $: - $ 2 \leq n_k \leq 10^5 $ - $ 0 \leq a_{k,i} < M $ for all $ i \in \{1, \dots, n_k\} $ **Objective** For each test case $ k $, and for each element $ a_{k,i} $, compute: $$ b_{k,i} = \max_{\substack{j \in \{1, \dots, n_k\} \\ j \neq i}} \left( (a_{k,i} + a_{k,j}) \bmod M \right) $$ Output the sequence $ (b_{k,1}, b_{k,2}, \dots, b_{k,n_k}) $.
API Response (JSON)
{
  "problem": {
    "name": "C. Large Summation",
    "description": {
      "content": "You are given an array a consisting of n element a1, a2, ..., an. For each element ai you must find another element aj (i ≠ j), such that the summation of ai and aj mod (109 + 7) (i.e. (ai + aj) % (10",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10153C"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given an array a consisting of n element a1, a2, ..., an. For each element ai you must find another element aj (i ≠ j), such that the summation of ai and aj mod (109 + 7) (i.e. (ai + aj) % (10...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case $ k \\in \\{1, \\dots, T\\} $:  \n- Let $ n_k \\in \\mathbb{Z} $ denote the size of the array, with $ 2 \\leq n_k \\...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments