eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Guessing Game

Guessing Game

Jaehyun has two lists of integers, namely \textbf{a_1}, ..., \textbf{a_N} and \textbf{b_1}, ..., \textbf{b_M }. Jeffrey wants to know what these numbers are, but Jaehyun won’t tell him the numbers directly. So, Jeffrey asks Jaehyun a series of questions of the form "How big is \textbf{a_i+b_j} ?" Jaehyun won’t even tell him that, though; instead, he answers either "It’s at least \textbf{c}," or "It’s at most \textbf{c}." (Right, Jaehyun simply doesn’t want to give his numbers for whatever reason.) After getting Jaehyun’s responses, Jeffrey tries to guess the numbers, but he cannot figure them out no matter how hard he tries. He starts to wonder if Jaehyun has lied while answering some of the questions. Write a program to hep Jeffrey. \InputFile The input consists of multiple test cases. Each test case begins with a line containing three positive integers \textbf{N}, \textbf{M}, and \textbf{Q}, which denote the lengths of the Jaehyun’s lists and the number of questions that Jeffrey asked. These numbers satisfy \textbf{2} ≤ \textbf{N + M} ≤ \textbf{1000} and \textbf{1} ≤ \textbf{Q} ≤ \textbf{10000}. Each of the next \textbf{Q} lines is of the form \textbf{i j} \textbf{<=} \textbf{c} or \textbf{i j} \textbf{>=} \textbf{c}. The former represents \textbf{a_i + b_j} ≤ _c, and the latter represents \textbf{a_i + b_j} ≥ \textbf{c}. It is guaranteed that \textbf{−1000} ≤ \textbf{c} ≤ \textbf{1000}. The input terminates with a line with \textbf{N = M = Q = 0}. \OutputFile For each test case, print a single line that contains "\textbf{Possible}" if there exist integers \textbf{a_1}, ..., \textbf{a_N} and \textbf{b_1}, ..., \textbf{b_M }that are consistent with Jaehyun’s answers, or "\textbf{Impossible}" if it can be proven that Jaehyun has definitely lied (quotes added for clarity).
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
2 1 3
1 1 <= 3
2 1 <= 5
1 1 >= 4
2 2 4
1 1 <= 3
2 1 <= 4
1 2 >= 5
2 2 >= 7
0 0 0
Вихідні дані #1
Impossible
Possible
Джерело 2011 Stanford Local ACM Programming Contest, Saturday, October 8th, 2011