A10192 | Bear and Fair Set
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $5k+1$ ,  elements of the form $5k+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".
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 $5k+1$ ,  elements of the form $5k+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".
输入格式
The first line contains three integers $n$ , $b$ and $q$ ( $5<=n<=b<=10^{4}$ , $1<=q<=10^{4}$ , $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$ ).
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$ ).
输出格式
Print ''fair" if there exists at least one set that has all the required properties and matches all the given hints. Otherwise, print ''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 :-(
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 :-(
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted