-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBusinessTrip.java
More file actions
42 lines (37 loc) · 875 Bytes
/
BusinessTrip.java
File metadata and controls
42 lines (37 loc) · 875 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
38
39
40
41
42
/* https://codeforces.com/contest/149/problem/A
tag: #greedy #implementation #sorting
* short the array in the descending order
* sum of any element that greater or equal k
* */
import java.util.Arrays;
import java.util.Scanner;
public class BusinessTrip {
static int calMinMonthNeeded() {
Scanner sc = new Scanner(System.in);
int k = sc.nextInt();
int[] arr = new int[12];
for (int i = 0; i < 12; i++) {
int temp = sc.nextInt();
arr[i] = temp;
}
Arrays.sort(arr);
// special case
if (k == 0) return 0;
int count = 0;
int sum = 0;
for (int i = 11; i >= 0; i--) {
sum += arr[i];
count++;
if (sum >= k) {
break;
}
}
if (sum < k) {
count = -1;
}
return count;
}
public static void main(String[] args) {
System.out.println(calMinMonthNeeded());
}
}