Skip to content

Commit e59e097

Browse files
committed
update
1 parent 06fcea0 commit e59e097

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Time: 405 ms
2+
// Memory: 1300 KB
3+
// Greedy.
4+
// T:O(sum(ni)), S:O(max(ni))
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1988B_Make_Majority {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int t = sc.nextInt();
12+
for (int i = 0; i < t; i++) {
13+
int n = sc.nextInt(), count0 = 0, count1 = 0;
14+
String s = sc.next();
15+
char prev = ' ';
16+
for (int j = 0; j < n; j++) {
17+
char c = s.charAt(j);
18+
if (prev == ' ') {
19+
int k = c == '0' ? count0++ : count1++;
20+
} else {
21+
if (prev != c) {
22+
int k = c == '0' ? count0++ : count1++;
23+
} else if (c == '1') {
24+
count1++;
25+
}
26+
}
27+
prev = c;
28+
}
29+
30+
System.out.println(count1 > count0 ? "YES" : "NO");
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)