NKTEAM - Team Selection

no tags 

The Interpeninsular Olympiad in Informatics is coming and the leaders of the Balkan Peninsula Team have to choose the best contestants on the Balkans. Fortunately, the leaders could choose the members of the team among N very good contestants, numbered from 1 to N (3 ≤ N ≤ 500000). In order to select the best contestants the leaders organized three competitions. Each of the N contestants took part in all three competitions and there were no two contestants with equal results on any of the competitions. We say that contestant А is better than another contestant В when А is ranked before В in all of the competitions. A contestant A is said to be excellent if no other contestant is better than A. The leaders of the Balkan Peninsula Team would like to know the number of excellent contestants.

Write a program, which for given N and the three competitions results, computes the number of excellent contestants.


The input data are given as four lines. The first line contains the number N. The next three lines show the rankings for the three competitions. Each of these lines contains the identification numbers of the contestants, separated by single spaces, in the order of their ranking from first to last place.


The output should contain one line with a single number written on it: the number of the excellent.


2 3 1
3 1 2
1 2 3


Note: No contestant is better than any other contestant, hence all three are excellent.

2 5 3 8 10 7 1 6 9 4
1 2 3 4 5 6 7 8 9 10
3 8 7 10 5 4 1 2 6 9


Note: The excellent contestants are those numbered with 1, 2, 3 and 5.

hide comments
fardin_abir: 2019-11-02 20:35:04

Donno why here is showing 18.18 as verdict...

desik_1: 2017-06-22 17:09:48

@A. Kaushik it is 2, even I got confused first.

Last edit: 2017-06-23 17:45:53
r_ash: 2017-05-31 17:01:18

My solution runs in nlog(n) still gives only 9.09 points. What is the best complexity?

A. Kaushik: 2016-09-15 22:06:49

can someone please explain how 2nd testcase has output 4? It looks like the output should be 2 for users 1, 7, have no other contestant better than them in all 3 cases? I am a bit confused in how the result should be interpreted.

Last edit: 2016-09-15 22:29:31
siddiboy: 2016-07-05 21:29:48

Nice problem!!!

windower: 2015-06-30 18:41:43

what is the result judging criteria ??

Last edit: 2015-06-30 18:43:51
NISHANT RAJ: 2014-10-15 21:11:07

constrain given is 3<=n<=500000 but it is no test case is containing n>100000

Hayk Saribekyan: 2009-08-20 13:02:55

The same task in classical section: NICEDAY. Only I/O format is different.

ashish: 2009-03-26 22:21:41

how can i know the no. of submissions for each problem..??

Added by:Jimmy
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:Balkan OI 2004