-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzcoprep.java
176 lines (139 loc) · 5.2 KB
/
zcoprep.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import java.util.*;
class zcoprep
{
boolean ish(int H[],int N)
{
int flag=0;
for (int i=0;i<N;i++)
{
if(!(1<=H[i]&&H[i]<=50))
{
flag=1;
}
}
if (flag==1)
return false;
else
return true;
}
void prog(int T)
{
String sel="";int count=0;
Scanner sc=new Scanner(System.in);
int M=0,N=0,S=0;
//getting the input here then
//T=sc.nextInt();
String s=sc.nextLine();
StringTokenizer st=new StringTokenizer(s);
N=Integer.parseInt(st.nextToken());
M=Integer.parseInt(st.nextToken());
S=Integer.parseInt(st.nextToken());
int H[]=new int[N];
String s1=sc.nextLine();
StringTokenizer st1=new StringTokenizer(s1);
for(int i=0;i<N;i++)
{
H[i]=Integer.parseInt(st1.nextToken());
}
if (1<=T&&T<=10&&1<=N&&N<=Math.pow(10,5)&&1<=M&&M<=Math.pow(10,5)&&1<=S&&S<=16&&ish(H,N))
{
for (int j=0;j<N;j++)
{
//System.out.println(H[j]);
if(H[j]<=S&&count<=M)
{
count++;
sel+=Integer.toString(H[j])+" ";
}
}
for (int i=0;i<N;i++)
{
if(H[i]>S&&count<=M&&(H[i]/2)<=S)
{
count+=1;
//sel+=Integer.toString(H[i])+" ";
}
}
}
System.out.println(count);
}
public static void main(String[]args)
{
zcoprep obj=new zcoprep();
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
for(int i=1;i<=T;i++)
obj.prog(T);
}
}
/*
* All submissions for this problem are available.The ZCO scholarship contest offers scholarships to first time ZCO participants. You are participating in it for the first time. So you want to know the number of participants who'll get the scholarship.
You know that the maximum number of scholarships offered is R
and there are a total of N participants numbered from 1 to N. Out of these, you know the set of people (denoted by X
) who you know, had participated in previous year ZCOs and hence, they shall not get the scholarship.
Further, as the world isn't free from plagiarism, so is the case with the scholarship contest. And from your secret sources, you also know the set of people (denoted by set Y
) who were involved in plagiarism and therefore aren't eligible for scholarship either.
Find out the number of participants who shall get the scholarship.
PS: Don't ask how so many scholarships are being offered when you see the constraints on R
. You never questioned it when in mathematics classes, some person bought 80 watermelons twice just to compare them and save ₹1
.
Input:
The first line will contain a single integer, T
, the number of testcases. Then the testcases follow.
The first line of each test case contains four integers; N
, R, |X| and |Y|
denoting the number of participants, maximum number of scholarships offered, number of old participants, and the number of participants involved in plagiarism, respectively.
The second line of each test case contains |X|
space separated integers x1,x2…x|X| denoting the indices of people who participated in previous years. If X
is empty, this line is skipped and no empty line is in the input.
The third line of each test case contains |Y|
space separated integers y1,y2…y|Y| denoting the indices of people who are involved in plagiarism. If Y
is empty, this line is skipped and no empty line is in input.
Output:
For each testcase, print a single integer in a new line, denoting the number of participants who shall get the scholarship.
Constraints
1≤T≤1000
1≤N≤1015
0≤R≤1015
0≤|X|,|Y|≤min(N,2∗105)
1≤xi,yi≤N
All xi
are distinct
All yi
are distinct
Sum of |X|
over all test cases does not exceed 5∗105
Sum of |Y|
over all test cases does not exceed 5∗105
Subtasks
20 points : 1≤N≤103
, and the sum of N over all test cases does not exceed 3∗103
30 points : 1≤N≤2∗105
, and the sum of N over all test cases does not exceed 5∗105
50 points: Original constraints
Sample Input:
3
5 3 0 1
4
10 2 4 6
3 1 7 6
4 3 1 5 9 7
10 4 4 6
3 1 7 6
4 3 1 5 9 7
Sample Output:
3
2
3
EXPLANATION:
In the first testcase, only participant 4
is involved in plagiarism, and thus not eligible for the scholarship. No user has participated in previous years, and so no empty line is there in the sample. All participants except participant 4 are eligible for the scholarship, but only three of them get it because R=3
.
Both second and third testcases are the same, except for R
. In both samples, only participants 2, 8 and 10
are eligible for scholarships.
In the second testcase, since the maximum number of scholarships is 2
, only 2
participants get scholarships.
In the third testcase, all three eligible participants get scholarships.
*/