-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUva10541.java
More file actions
44 lines (41 loc) · 1.33 KB
/
Copy pathUva10541.java
File metadata and controls
44 lines (41 loc) · 1.33 KB
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
/* @author : mostafa
* created : 2018-08-17 00:19
*/
import java.util.*;
import java.io.* ;
import java.math.BigInteger ;
public class Uva10541
{
public static void main(String [] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pr = new PrintWriter(System.out);
StringBuilder sb = new StringBuilder();
int tc = Integer.parseInt(br.readLine());
while( tc--> 0 ){
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt( st.nextToken() ) ;
int k = Integer.parseInt( st.nextToken() ) ;
for(int i = 0 ; i < k ; i++){
int x = Integer.parseInt( st.nextToken() );
n -= x ;
}
n++ ;
if( k > n ){
sb.append(0).append('\n');
continue ;
}
BigInteger ans = BigInteger.ONE ;
for(int i = n ; i > n-k ; i--){
ans = ans.multiply(BigInteger.valueOf(i));
}
for(int i = k ; i > 1 ; i--){
ans = ans.divide(BigInteger.valueOf(i));
}
sb.append(ans.toString()).append('\n');
}
pr.print(sb.toString());
pr.close();
br.close();
}
}