A8401 | Unlucky Ticket
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket is lucky. Let us remind you that a ticket is lucky if the sum of digits in its first half matches the sum of digits in its second half.
But of course, not every ticket can be lucky. Far from it! Moreover, sometimes one look at a ticket can be enough to say right away that the ticket is not lucky. So, let's consider the following unluckiness criterion that can definitely determine an unlucky ticket. We'll say that a ticket is definitely unlucky if each digit from the first half corresponds to some digit from the second half so that each digit from the first half is strictly less than the corresponding digit from the second one or each digit from the first half is strictly more than the corresponding digit from the second one. Each digit should be used exactly once in the comparisons. In other words, there is such bijective correspondence between the digits of the first and the second half of the ticket, that either each digit of the first half turns out strictly less than the corresponding digit of the second half or each digit of the first half turns out strictly more than the corresponding digit from the second half.
For example, ticket $2421$ meets the following unluckiness criterion and will not be considered lucky (the sought correspondence is $2>1$ and $4>2$ ), ticket $0135$ also meets the criterion (the sought correspondence is $0<3$ and $1<5$ ), and ticket $3754$ does not meet the criterion.
You have a ticket in your hands, it contains $2n$ digits. Your task is to check whether it meets the unluckiness criterion.
But of course, not every ticket can be lucky. Far from it! Moreover, sometimes one look at a ticket can be enough to say right away that the ticket is not lucky. So, let's consider the following unluckiness criterion that can definitely determine an unlucky ticket. We'll say that a ticket is definitely unlucky if each digit from the first half corresponds to some digit from the second half so that each digit from the first half is strictly less than the corresponding digit from the second one or each digit from the first half is strictly more than the corresponding digit from the second one. Each digit should be used exactly once in the comparisons. In other words, there is such bijective correspondence between the digits of the first and the second half of the ticket, that either each digit of the first half turns out strictly less than the corresponding digit of the second half or each digit of the first half turns out strictly more than the corresponding digit from the second half.
For example, ticket $2421$ meets the following unluckiness criterion and will not be considered lucky (the sought correspondence is $2>1$ and $4>2$ ), ticket $0135$ also meets the criterion (the sought correspondence is $0<3$ and $1<5$ ), and ticket $3754$ does not meet the criterion.
You have a ticket in your hands, it contains $2n$ digits. Your task is to check whether it meets the unluckiness criterion.
输入格式
The first line contains an integer $n$ ( $1<=n<=100$ ). The second line contains a string that consists of $2n$ digits and defines your ticket.
输出格式
In the first line print "YES" if the ticket meets the unluckiness criterion. Otherwise, print "NO" (without the quotes).
输入输出样例
输入 #1
2 2421
输出 #1
YES
输入 #2
2 0135
输出 #2
YES
输入 #3
2 3754
输出 #3
NO
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted