Problem:
Score : 600 points

Problem Statement

Given are two integer sequences of N elements each: A_1,...,A_N and B_1,...,B_N.
Determine if it is possible to do the following operation at most N-2 times (possibly zero) so that, for every integer i from 1 to N, A_i \leq B_i holds:

Choose two distinct integers x and y between 1 and N (inclusive), and swap the values of A_x and A_y.

Constraints

2 \leq N \leq 10^5

1 \leq A_i,B_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N

Output

If the objective is achievable, print Yes; if it is not, print No.

Sample Input 1

3
1 3 2
1 2 3

Sample Output 1

Yes

We should swap the values of A_2 and A_3.

Sample Input 2

3
1 2 3
2 2 2

Sample Output 2

No

Sample Input 3

6
3 1 2 6 3 4
2 2 8 3 4 3

Sample Output 3

Yes

Solution in Go (1.6) (judge verdict: Wrong Answer)

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

type Perm struct {
	idx int
	num int
}

type Perms []Perm

func (p Perms) Len() int {
	return len(p)
}

func (p Perms) Less(i, j int) bool {
	return p[i].num < p[j].num
}

func (p Perms) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func swaps(n int, a, b []int) bool {
	// まず巡回置換 (p1, ..., pN ) を Ap1 ≦ Ap2 ≦ ... ≦ ApN となるようにとる
	ap := make([]int, 0, n)
	for _, v := range a {
		ap = append(ap, v)
	}
	sort.Ints(ap)
	bp := make([]int, 0, n)
	for _, v := range b {
		bp = append(bp, v)
	}
	sort.Ints(bp)

	// このとき Api ≦ Bi(i = 1, ..., N ) が成り立たなければ、1 つめの条件をみたす (p1 , ..., pN ) が存在しないので、false
	for i := 0; i < n; i++ {
		if ap[i] > bp[i] {
			return false
		}

	}

	// Api ≦ Bi(i = 1,...,N) となる場合
	// 巡回置換(p1,...,pN)をサイクルに分解したときに、2つ以上のサイクルに分解されるならば、true
	// N-1回あればできるやつ
	// a をsortすると順序が変わってしまうので最初に処理する
	// 時間計算量が増える。。。
	perms := make([]Perm, n)
	for i, v := range a {
		perms[i] = Perm{idx: i, num: v}
	}

	sort.Sort(Perms(perms))

	p := make([]int, 0, n)
	for _, perm := range perms {
		p = append(p, perm.idx)
	}
	// 目標位置をswapできる場所があれば、達成可能
	for i := 0; i < n-1; i++ {
		if p[i+1] <= bp[i] {
			return true
		}
	}

	// この時点で、Aは相異なり、目標インデックスも1つに決まる
	count := 0
	x := 0
	for x != 0 {
		count++
		x = p[x]
	}

	return count < n
}

func main() {
	sc := bufio.NewScanner(os.Stdin)

	var n int
	if sc.Scan() {
		n, _ = strconv.Atoi(sc.Text())
	}

	a := make([]int, n)
	if sc.Scan() {
		ss := strings.Split(sc.Text(), " ")
		for i := range ss {
			a[i], _ = strconv.Atoi(ss[i])
		}
	}

	b := make([]int, n)
	if sc.Scan() {
		ss := strings.Split(sc.Text(), " ")
		for i := range ss {
			b[i], _ = strconv.Atoi(ss[i])
		}
	}

	if swaps(n, a, b) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}