F. Lonely Dreamoon 2

Codeforces
IDCF10123F
Time1000ms
Memory512MB
Difficulty
English · Original
Formal · Original
Dreamoon, who doesn't have a girlfriend, often goes for a walk along some streets in Taipei while thinking about problems from algorithm competitions. Unfortunately, there are so many couples acting lovey-dovey on the street that Dreamoon can not focus on thinking about those problems. One day, despite the love birds everywhere, Dreamoon discovered a problem input containing an integer sequence: a1, a2, a3, ..., aN. Dreamoon thought: because I'm single, every pair of consecutive numbers should have a large difference! This is, Dreamoon wants to reorder the sequence to make the value as large as possible. So Dreamoon turned on Drazil, who does have a girlfriend, and forced Drazil to fulfill the above condition by reordering the integer sequence. Please help poor Drazil  > _ <  The input consists of two lines. The first line contains an integer N. The second line consists of N integers a1, a2, ..., aN. Output a single line consisting of N integers, denoting the integer sequence a after reordering. For this reordering, the value must be the largest possible among all reorderings of the input sequence. If there are several possible answers, output any one of them. ## Input The input consists of two lines. The first line contains an integer N. The second line consists of N integers a1, a2, ..., aN. 2 ≤ N ≤ 2 × 105  - 109 ≤ ai ≤ 109 ## Output Output a single line consisting of N integers, denoting the integer sequence a after reordering. For this reordering, the value must be the largest possible among all reorderings of the input sequence. If there are several possible answers, output any one of them. [samples]
**Definitions** Let $ N \in \mathbb{Z}^+ $ be the length of the sequence. Let $ A = (a_1, a_2, \dots, a_N) $ be a sequence of real numbers. **Objective** Find a permutation $ B = (b_1, b_2, \dots, b_N) $ of $ A $ that maximizes: $$ \sum_{i=1}^{N-1} |b_i - b_{i+1}| $$ **Constraints** - $ 1 \leq N \leq 100 $ - $ a_i \in \mathbb{R} $ for all $ i \in \{1, \dots, N\} $ (typically integers in practice)
API Response (JSON)
{
  "problem": {
    "name": "F. Lonely Dreamoon 2",
    "description": {
      "content": "Dreamoon, who doesn't have a girlfriend, often goes for a walk along some streets in Taipei while thinking about problems from algorithm competitions. Unfortunately, there are so many couples acting l",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 524288
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10123F"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Dreamoon, who doesn't have a girlfriend, often goes for a walk along some streets in Taipei while thinking about problems from algorithm competitions. Unfortunately, there are so many couples acting l...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ N \\in \\mathbb{Z}^+ $ be the length of the sequence.  \nLet $ A = (a_1, a_2, \\dots, a_N) $ be a sequence of real numbers.\n\n**Objective**  \nFind a permutation $ B = (b_1, b_2, \\do...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments