CF628F.Bear and Fair Set
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Limak is a grizzly bear. He is big and dreadful. You were chilling in the forest when you suddenly met him. It's very unfortunate for you. He will eat all your cookies unless you can demonstrate your mathematical skills. To test you, Limak is going to give you a puzzle to solve.
It's a well-known fact that Limak, as every bear, owns a set of numbers. You know some information about the set:
- The elements of the set are distinct positive integers.
- The number of elements in the set is n. The number n is divisible by 5.
- All elements are between 1 and b, inclusive: bears don't know numbers greater than b.
- For each r in {0, 1, 2, 3, 4}, the set contains exactly
elements that give remainder r when divided by 5. (That is, there are
elements divisible by 5,
elements of the form 5_k_ + 1,
elements of the form 5_k_ + 2, and so on.)
Limak smiles mysteriously and gives you q hints about his set. The i-th hint is the following sentence: "If you only look at elements that are between 1 and upTo__i, inclusive, you will find exactly quantity__i such elements in my set."
In a moment Limak will tell you the actual puzzle, but something doesn't seem right... That smile was very strange. You start to think about a possible reason. Maybe Limak cheated you? Or is he a fair grizzly bear?
Given n, b, q and hints, check whether Limak can be fair, i.e. there exists at least one set satisfying the given conditions. If it's possible then print ''fair". Otherwise, print ''unfair".
Limak 是一只灰熊,体型庞大且令人畏惧。你正在森林中放松,却突然遇见了他——这对你来说非常不幸。除非你能展示自己的数学能力,否则他将吃掉你所有的饼干。为了考验你,Limak 将给你一道谜题来解答。
众所周知,Limak(像所有熊一样)拥有一组数字。你对这组数字已知以下信息:
- 该集合中的元素是互不相同的正整数;
- 集合的元素个数为 n,且 n 能被 5 整除;
- 所有元素均在 1 到 b 之间(含端点):熊不知道大于 b 的数;
- 对每个 r∈{0,1,2,3,4},集合中恰好有
个元素模 5 余 r。(即:恰好有
个元素能被 5 整除,
个形如 5k+1 的元素,
个形如 5k+2 的元素,依此类推。)
Limak 神秘地一笑,给了你 q 条关于他集合的提示。第 i 条提示如下:“若只考虑 1 到 upToi(含端点)之间的元素,则我的集合中恰好有 quantityi 个这样的元素。”
片刻之后,Limak 就要告诉你真正的谜题了,但某些地方似乎不太对劲……那笑容非常诡异。你开始思考可能的原因:也许 Limak 欺骗了你?抑或他其实是一只公正的灰熊?
给定 n、b、q 及所有提示,判断 Limak 是否可能公正,即:是否存在至少一个满足上述所有条件的集合。若存在,则输出 fair;否则输出 unfair。
输入格式
The first line contains three integers n, b and q (5 ≤ n ≤ b ≤ 104, 1 ≤ q ≤ 104, n divisible by 5) — the size of the set, the upper limit for numbers in the set and the number of hints.
The next q lines describe the hints. The i-th of them contains two integers upTo__i and quantity__i (1 ≤ upTo__i ≤ b, 0 ≤ quantity__i ≤ n).
第一行包含三个整数 n、b 和 q(5 ≤ n ≤ b ≤ 104,1 ≤ q ≤ 104,且 n 能被 5 整除)—— 分别表示集合的大小、集合中数字的上限以及提示的数量。
接下来的 q 行描述这些提示。其中第 i 行包含两个整数 upToi 和 quantityi(1 ≤ upToi ≤ b,0 ≤ quantityi ≤ n)。
输出格式
Print ''fair" if there exists at least one set that has all the required properties and matches all the given hints. Otherwise, print ''unfair".
如果存在至少一个集合,该集合满足所有必需的性质且与所有给定的提示相匹配,则输出 fair'';否则,输出 unfair''。
输入输出样例
输入#1
10 20 1 10 10
输出#1
fair
输入#2
10 20 3 15 10 5 0 10 5
输出#2
fair
输入#3
10 20 2 15 3 20 10
输出#3
unfair
说明/提示
In the first example there is only one set satisfying all conditions: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.
In the second example also there is only one set satisfying all conditions: {6, 7, 8, 9, 10, 11, 12, 13, 14, 15}.
Easy to see that there is no set satisfying all conditions from the third example. So Limak lied to you :-(
在第一个例子中,只有一个集合满足所有条件:{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}。
在第二个例子中,同样也只有一个集合满足所有条件:{6, 7, 8, 9, 10, 11, 12, 13, 14, 15}。
容易看出,第三个例子中不存在满足所有条件的集合。因此 Limak 对你撒谎了 :-(
输入解题思路,AI测评打分。不知道怎么写?