codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

160B.md (2394B)


      1 Source: https://codeforces.com/problemset/problem/160/B
      2 
      3 B. Unlucky Ticket
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 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.
     22 
     23 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.
     24 
     25 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.
     26 
     27 You have a ticket in your hands, it contains 2*n* digits. Your task is to check whether it meets the unluckiness criterion.
     28 
     29 Input
     30 
     31 The first line contains an integer *n* (1 ≤ *n* ≤ 100). The second line contains a string that consists of 2*n* digits and defines your ticket.
     32 
     33 Output
     34 
     35 In the first line print "YES" if the ticket meets the unluckiness criterion. Otherwise, print "NO" (without the quotes).
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 2  
     43 2421
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 YES
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 2  
     56 0135
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 YES
     63 ```
     64 
     65 Input
     66 
     67 ```
     68 2  
     69 3754
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 NO
     76 ```