-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBooks.java
More file actions
37 lines (28 loc) · 960 Bytes
/
Books.java
File metadata and controls
37 lines (28 loc) · 960 Bytes
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
/**
* Created by MalhotR1 on 05/16/2018.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Books {
public static void main(String[] args) throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
String[] in = br.readLine().trim().split(" ");
int n = Integer.parseInt(in[0]);
int f = Integer.parseInt(in[1]);
in = br.readLine().trim().split(" ");
int[] arr = new int[in.length];
for (int i = 0; i < arr.length; i++) {
arr[i] = Integer.parseInt(in[i]);
}
Arrays.sort(arr);
int index = 0;
while (index < arr.length && f > 0 && f >= arr[index]) {
f -= arr[index];
index++;
}
System.out.println(index);
}
}
}