-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdareToCompete.java
93 lines (81 loc) · 1.8 KB
/
dareToCompete.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
import java.util.Arrays;
import java.util.Scanner;
public class dareToCompete {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
//
int n = scn.nextInt();
//
// int[][] arr = new int[n][n];
//
// for (int i = 0; i < arr.length; i++) {
// for (int j = 0; j < arr.length; j++) {
// arr[i][j] = scn.nextInt();
// }
// }
// // new int[][] { { -1, 0, 0 }, { 0, -1, 1 }, { 0, 2, -1 } }
// carsCollide(arr);
int[] arr = new int[n];
for (int i = 0; i < arr.length; i++) {
arr[i] = scn.nextInt();
}
disappointed(arr);
}
public static void carsCollide(int[][] arr) {
boolean[] boolArr = new boolean[arr.length];
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if (arr[i][j] == -1) {
continue;
} else if (arr[i][j] == 0) {
continue;
} else if (arr[i][j] == 1) {
boolArr[i] = true;
} else if (arr[i][j] == 2) {
boolArr[j] = true;
} else if (arr[i][j] == 3) {
boolArr[i] = true;
boolArr[j] = true;
}
}
}
int count = 0;
for (int i = 0; i < boolArr.length; i++) {
if (!boolArr[i]) {
count += 1;
}
}
System.out.println(count);
for (int i = 0; i < boolArr.length; i++) {
if (!boolArr[i]) {
System.out.print((i + 1) + " ");
}
}
}
public static void disappointed(int[] arr) {
Arrays.sort(arr);
int count = 0;
int sum = 0;
for (int i = 0; i < arr.length; i++) {
if (sum <= arr[i]) {
count++;
}
sum += arr[i];
}
System.out.println(count);
}
private static class treeCutClass {
int x;
int h;
String LR;
public treeCutClass(int x, int h, String LR) {
this.x = x;
this.h = h;
this.LR = LR;
}
}
public static int treeCut(treeCutClass[] arr, int i) {
arr[i].LR = "left";
int count = treeCut(arr, i);
}
}