#FT0000150. Tuyển chọn đội tuyển (Team Selection)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tuyển chọn đội tuyển (Team Selection)
Team Selection
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
There are contestants with identifiers through , who take part in three competitions. Each competition provides one complete ranking, from best to worst. As there are no ties, every ranking is a permutation of .
Contestant is better than contestant if ranks ahead of in all three competitions. A contestant is excellent if there exists no other contestant better than them.
Count the excellent contestants. Only their number is required.
Input
The first line contains . Each of the next three lines is a permutation listing all contestant IDs from the first-ranked to the last-ranked in one competition.
Output
Print one integer: the number of excellent contestants.
Subtasks
- Subtask 1 (20 points): ; each competition ranking is a complete permutation of with no ties.
- Subtask 2 (30 points): ; each competition ranking is a complete permutation of with no ties.
- Subtask 3 (50 points): ; each competition ranking is a complete permutation of with no ties.
Examples
Example 1
Input
3
2 3 1
3 1 2
1 2 3
Output
3
Explanation
Rank triples are contestant 1: , contestant 2: , contestant 3: . No contestant ranks ahead of another in all three contests, so all three are excellent.
Example 2
Input
4
1 2 3 4
1 2 3 4
1 2 3 4
Output
1
Explanation
Contestant 1 ranks first in all three competitions, beating contestants 2, 3, and 4 simultaneously. No contestant outranks contestant 1, so exactly one contestant is excellent.