CF Duels

시간 제한2초메모리 제한2048 MB

요약
상대 선수의 능력치를 앞에서부터 몇 개나 알아야 우리 팀의 우승을 보장하는 배정이 가능한지 최소 개수를 구한다.
난이도

보통10점 중 7점

유형
그리디, 정렬, 투 포인터, 이분 탐색
정답자
아직 제출이 없습니다

문제

Two football teams, each consisting of exactly NN players, from Chisinau, the capital of Moldova, hold a set of duels (Chisinau Football Duels). To make it interesting, they organize the football match-ups in the following 11 vs 11 format:

  • There will be a total of NN duels, each held in a different stadium.
  • Each duel will have exactly one player from each of the two teams.
  • Each player will take part in exactly one duel.
  • Each stadium will provide a certain amount of prize money for the winner of the respective duel.
  • The player with the higher skill level wins the duel. It is guaranteed that there is always a player with a higher skill level.

The champion is the team that has obtained a strictly greater amount of prize money than the opponent team after all the matches. In case of an equal obtained prize money, there is no champion.

You are the manager of the first football team, and your job is to strategically assign your NN players to the NN duels.

As the manager of the first football team, you have the following information:

  • NN integers, representing the skill levels of your team's players
  • NN integers, representing the skill levels of the opposing team's players

As the manager, you also sent a scout to visit each stadium. The scout visits the stadiums in increasing order from 11 to NN, meaning he will visit stadium 11 first, then stadium 22, and will end at stadium NN. After the scout visits stadium ii, he will give you information regarding the skill level of the opposing team's duelist at stadium ii.

Possibly, after the scout visits some stadiums, you can already foresee your team emerging as a champion. In other words, there is a possibility that, after your scout visits some stadiums, you will be certain that you can become the champion. You may still need to wait for the scout to visit the rest of the stadiums in order to be able to build an assignment for your team.

Your task is to find out the minimal number of stadiums the scout has to visit for you to be certain about that your team securing the championship, or figure out that it's impossible to become the champion.

입력

The first line of input will contain the integer NN (1≤N≤5⋅1041 ≤ N ≤ 5 \cdot 10^4), denoting the number of duels, players per team and stadiums.

The second line will contain NN integers p_1,p_2,…,p_Np\_1 , p\_2 , …, p\_N (1≤p_i≤1061 ≤ p\_i ≤ 10^6), representing the prize money offered by stadiums 1,2,…,N1, 2, \dots , N, respectively.

The third line contains NN integers b_1,b_2,…,b_Nb\_1 , b\_2 , \dots , b\_N (1≤b_i≤1061 ≤ b\_i ≤ 10^6), b_ib\_i representing the skill level reported by the scout of the opponent player in stadium ii. (Note that this information already contains the skill levels of each of the players in the opponent team, so they are not given once again to remove redundancy).

The fourth line contains NN integers a_1,a_2,…,a_Na\_1 , a\_2 , \dots , a\_N (1≤a_i≤1061 ≤ a\_i ≤ 10^6), representing the skill levels of the players in your team.

출력

Output a single integer - the minimum number of stadiums you need information about to be certain your team can be the champion.

Additionally, you should output 00 in case you immediately know your team will be the champion in any case, or −1-1 if you can not find a winning strategy even after you have information of all the NN stadiums.

제한

  • 1≤N≤5⋅1041 ≤ N ≤ 5 \cdot 10^4.
  • 1≤a_i,b_i,p_i≤1061 ≤ a\_i , b\_i , p\_i ≤ 10^6 for all (1≤i≤N1 ≤ i ≤ N).
  • Additionally, the skill levels of all the players are distinct. In other words for any (i,j)(i, j) a_i≠b_ja\_i \ne b\_j And for any (i,j)(i, j) (i≠ji \ne j) a_i≠a_ja\_i \ne a\_j and b_i≠b_jb\_i \ne b\_j.

예제4

  1. 예제 1

    입력
    5
    1 5 4 3 1
    5 9 3 12 8
    1 10 4 2 6
    
    예상 출력
    3
    
  2. 예제 2

    입력
    6
    6 1 21 22 23 24
    1 12 6 8 10 11
    2 3 4 5 7 9
    
    예상 출력
    2
    
  3. 예제 3

    입력
    3
    1 1 3
    3 4 6
    2 1 7
    
    예상 출력
    0
    
  4. 예제 4

    입력
    3
    1 1 3
    3 4 6
    2 1 5
    
    예상 출력
    -1