C. Very Spacious Office

Codeforces
IDCF10018C
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Programmers at the company «Perimeter» are working on n software projects. Their boss Shiftman understands the importance of comfortable working conditions. There is neither dress code nor fixed work schedule in the company, but there always is tea and fresh kiwis in the kitchen. When the team of the «Diplodocus» project complained that their room was too crowded after new employees had joined the company, Shiftman understood that it was time to search for a new spacious office. A new office building was found quickly. It was located near a subway station and a nice park. In addition, there was a large underground parking. The number of rooms in the office was the same as the number of projects in the company, so Shiftman decided to assign a room to each project, thus creating a unique work atmosphere for the teams. Project managers had their own notions of ideal room for their projects. Of course, the room should not be too small. However, if the room would be too big, the programmers might be afraid that a new team would be added to their room. Help the managers to assign the rooms quickly and without the boss's meddling. The first line contains the number n of projects in the company (1 ≤ n ≤ 100000). In the second line you are given n numbers, which are the areas of all the rooms in the new office. The i-th of the following n lines contains two numbers, which are the minimum and maximum areas of the room in which the team of the i-th project agrees to work (of course, the minimum area does not exceed the maximum area). All the areas are positive integers and do not exceed 109. If there is only one way to assign the rooms to the teams, output «_Perfect!_» in the first line and a permutation of integers from 1 to n in the second line. In this permutation, the i-th element must be the number of the room assigned to the team of the i-th project. The rooms are numbered from 1 to n in the order in which they are described in the input. If there are several ways to assign the rooms, output «_Ask Shiftman for help._» If it is impossible to assign the rooms as required, output «_Let's search for another office._» ## Input The first line contains the number n of projects in the company (1 ≤ n ≤ 100000). In the second line you are given n numbers, which are the areas of all the rooms in the new office. The i-th of the following n lines contains two numbers, which are the minimum and maximum areas of the room in which the team of the i-th project agrees to work (of course, the minimum area does not exceed the maximum area). All the areas are positive integers and do not exceed 109. ## Output If there is only one way to assign the rooms to the teams, output «_Perfect!_» in the first line and a permutation of integers from 1 to n in the second line. In this permutation, the i-th element must be the number of the room assigned to the team of the i-th project. The rooms are numbered from 1 to n in the order in which they are described in the input.If there are several ways to assign the rooms, output «_Ask Shiftman for help._»If it is impossible to assign the rooms as required, output «_Let's search for another office._» [samples]
**Definitions** Let $ N, M \in \mathbb{Z} $ be the dimensions of the grid, with $ 2 \leq N, M \leq 1000 $. Let $ G \in \{ \texttt{.} \} \cup \{ \texttt{a}, \dots, \texttt{z} \}^{N \times M} $ be the grid, where: - $ G[i][j] = \texttt{.} $ denotes an empty square (free for road), - $ G[i][j] \in \{ \texttt{a}, \dots, \texttt{z} \} $ denotes a square belonging to a private property (each letter identifies a unique connected rectangular property). Let $ P \subseteq \{1, \dots, N\} \times \{1, \dots, M\} $ be the set of all squares belonging to private properties. Let $ R \subseteq \{1, \dots, N\} \times \{1, \dots, M\} $ be a path from $ (1,1) $ to $ (N,M) $, consisting of unit-length horizontal/vertical segments, with no diagonal moves. **Constraints** 1. $ R $ must be a shortest path from $ (1,1) $ to $ (N,M) $: $ |R| = N + M - 1 $. 2. $ R $ must consist of grid squares with $ G[i][j] = \texttt{.} $ or $ G[i][j] \in \{ \texttt{a}, \dots, \texttt{z} \} $ (i.e., may traverse property squares). 3. The road must be connected and monotonic: each step moves either right or down. **Objective** Minimize the number of private property squares in $ R $: $$ K = \min_{R} \left| R \cap P \right| $$ Output $ K $ and the sequence of coordinates $ (i_1, j_1), (i_2, j_2), \dots, (i_{N+M-1}, j_{N+M-1}) $ of the minimizing path $ R $, starting at $ (1,1) $ and ending at $ (N,M) $, with each step moving only right or down.
API Response (JSON)
{
  "problem": {
    "name": "C. Very Spacious Office",
    "description": {
      "content": "Programmers at the company «Perimeter» are working on n software projects. Their boss Shiftman understands the importance of comfortable working conditions. There is neither dress code nor fixed work ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10018C"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Programmers at the company «Perimeter» are working on n software projects. Their boss Shiftman understands the importance of comfortable working conditions. There is neither dress code nor fixed work ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ N, M \\in \\mathbb{Z} $ be the dimensions of the grid, with $ 2 \\leq N, M \\leq 1000 $.  \nLet $ G \\in \\{ \\texttt{.} \\} \\cup \\{ \\texttt{a}, \\dots, \\texttt{z} \\}^{N \\times M} $ be t...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments