CodeForces 160B - Unlucky Ticket

B. Unlucky Ticket
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 suchbijective correspondence between the digits of the first and the second half of the ticket, that either each digit of the first half turns outstrictly 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 > 1and 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.

Input

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.

Output

In the first line print "YES" if the ticket meets the unluckiness criterion. Otherwise, print "NO" (without the quotes).

Sample test(s)
input
2
2421
output
YES
input
2
0135
output
YES
input
2
3754
output
NO


================================


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n,flag1=1,flag2=1,a[111],b[111];char str[222];
    cin>>n;
    cin>>str;
    for(int i=0;i<n;i++) a[i]=str[i]-'0';
    for(int i=n;i<2*n;i++) b[i-n]=str[i]-'0';
    sort(a,a+n);
    sort(b,b+n);
    
    for(int i=0;i<n;i++)
    {
        if(a[i]<=b[i])
        {
            flag1=0;
            break;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]>=b[i])
        {
            flag2=0;
            break;
        }
    }
    //cout<<flag1<<" "<<flag2<<endl;
    if(!flag1&&!flag2) printf("NO\n");
    else printf("YES\n");
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值