Skip to content

Commit 6c28d25

Browse files
committed
update
1 parent a176dd9 commit 6c28d25

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Time: 342 ms
2+
// Memory: 1300 KB
3+
// Greedy.
4+
// T:O(sum(ni)), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2019A_Max_Plus_Size {
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(), ret, maxVal = 0;
14+
boolean maxValEvenIndex = false;
15+
for (int j = 0; j < n; j++) {
16+
int a = sc.nextInt();
17+
if (a > maxVal) {
18+
maxVal = a;
19+
maxValEvenIndex = false;
20+
if (j % 2 == 0) {
21+
maxValEvenIndex = true;
22+
}
23+
} else if (a == maxVal) {
24+
if (j % 2 == 0) {
25+
maxValEvenIndex = true;
26+
}
27+
}
28+
}
29+
if (n % 2 == 0) {
30+
ret = n / 2 + maxVal;
31+
} else {
32+
if (maxValEvenIndex) {
33+
ret = maxVal + n / 2 + 1;
34+
} else {
35+
ret = maxVal + n / 2;
36+
}
37+
}
38+
39+
System.out.println(ret);
40+
}
41+
}
42+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Time: 359 ms
2+
// Memory: 1300 KB
3+
// brute-force.
4+
// T:O(sum(logni)), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2043A_Coin_Transformation {
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+
long n = sc.nextLong();
14+
int ret = 1;
15+
while (n >= 4) {
16+
n /= 4;
17+
ret *= 2;
18+
}
19+
System.out.println(ret);
20+
}
21+
}
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Time: 359 ms
2+
// Memory: 1200 KB
3+
// .
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2086A_Cloudberry_Jam {
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();
14+
15+
System.out.println(2 * n);
16+
}
17+
}
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Runtime 3 ms Beats 64.27%
2+
// Memory 72.73 MB Beats 71.33%
3+
// Greedy & Monotonic.
4+
// T:O(n), S:O(1)
5+
//
6+
class Solution {
7+
public int maximumPossibleSize(int[] nums) {
8+
int ret = 0, prev = 0;
9+
for (int num : nums) {
10+
if (num > prev) {
11+
ret++;
12+
prev = num;
13+
} else if (num == prev) {
14+
ret++;
15+
}
16+
}
17+
18+
return ret;
19+
}
20+
}

0 commit comments

Comments
 (0)