POJ 1364 King (difference constraint) __ graph theory

Source: Internet
Author: User
Tags integer numbers
Description

Once, in one kingdom, there is a queen and that Queen was expecting a baby. The Queen prayed: "If my child is a son and if only is a sound king." After nine months her is born, and indeed, she gave birth to a nice son.

Unfortunately, as it used to happen in royal families, the son was a little retarded. After many years of study him able just to add-integer numbers and to compare whether the ' result is greater or less tha n a given integer number. In addition, the numbers had to is written in a sequence and he is able to sum just continuous subsequences of the Sequen Ce.

The old King is very unhappy of his son. But He is ready to make everything to enable his son to govern the kingdom after his death. With regards to his son's skills he decided this every problem the king had to decide about had to is presented in a form of a finite sequence of an integer numbers and the decision about it would to do by stating an integer constraint (i.e. Upper or lower limit) for the sum of this sequence. In this way there is at least some hope, his son would is able to make some.

After the old king died, the young king began to reign. But very soon, a lot of people, became very with his unsatisfied and decisions to decided. They tried to does it by proving this his decisions were wrong.

Therefore some conspirators presented to "young king a set of problems" he had to decide about. The set of problems is in the form of subsequences Si = {aSi, asi+1, ..., asi+ni} of a sequence S = {A1, a2, ..., an}. The king thought a minute and then decided, i.e. he set for the sum aSi + asi+1 + ... + asi+ni of each subsequence Si an int Eger constraint Ki (i.e. asi + asi+1 + ... + asi+ni < Ki or aSi + asi+1 + ... + asi+ni > Ki resp.) and declared these Co Nstraints as his decisions.

After a while him realized that some of his decisions were wrong. He could not revoke the declared constraints but trying to save himself him decided to fake the sequence. He ordered to his advisors to find such a sequence S, would satisfy the constraints he set. Help the advisors of the King and write a, decides whether such a sequence exists or not.


Input

The input consists of blocks of lines. Each blocks except the last corresponds to one set of problems and King's decisions about them. In the the ' the ' block there are integers n, and m where 0 < n <=-length of the sequence S and 0 < M <= is the number of subsequences Si. Next m lines contain particular decisions coded in the form of Quadruples si, ni, oi, ki, where Oi represents operator ; (coded as GT) or operator < (coded as LT) respectively. The symbols si, ni and ki have the meaning described above. The last blocks consists of just one line containing 0.


Output

The output contains the lines corresponding to the blocks in the input. A line contains text successful conspiracy then such a sequence does not exist. Otherwise it contains text lamentable kingdom. There is no. in the output corresponding to the last "null" block of the input.


Sample Input

4 2
1 2 GT 0 2 2 LT 2 1 2 1 0
GT 0
1 0 lt 0
0


Sample Output

Lamentable Kingdom
Successful conspiracy


the

Suppose that there is currently such a sequence s=a1,a2,a3...an s={a_1,a_2,a_3...a_n}, now give some inequalities to make Ai+ai+1+ai+2+...+ai+n<ki a_i+a_{i+1}+a_{i+2}+ ... +a_{i+n} or Ai+ai+1+ai+2+...+ai+n>ki a_i+a_{i+1}+a_{i+2}+...+a_{i+n}>k_i, ask if such a sequence exists.


train of Thought

Sample Example:

1 2 GT 0 (a1+a2+a3>0) (a_1+a_2+a_3>0)

2 2 lt 2 (a2+a3+a4<2) (a_2+a_3+a_4

First we can set up Si=a1+a2+...+ai s_i=a_1+a_2+...+a_i

According to the sample example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.