diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..4f267ad --- /dev/null +++ b/Main.java @@ -0,0 +1,41 @@ +import java.util.Arrays; +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + task2(); + } + + static void task1() { + Scanner input = new Scanner(System.in); + String data = input.nextLine(); + + int day1 = Integer.parseInt(data.split(" ")[0]); + int day2 = Integer.parseInt(data.split(" ")[1]); + + if (day1 > 7) { + System.out.println(day1 - 7); + } else { + System.out.println(day2 + 7); + } + } + + static void task2() { + Scanner input = new Scanner(System.in); + String data = input.nextLine(); + + int cntA = 0, cntAB = 0, cntABC = 0; + + for (char c : data.toCharArray()) { + if (c == 'a') { + cntA++; + } else if (c == 'b') { + cntAB += cntA; + } else if (c == 'c') { + cntABC += cntAB; + } + } + + System.out.println(cntABC); + } +} \ No newline at end of file diff --git a/__pycache__/main.cpython-314.pyc b/__pycache__/main.cpython-314.pyc new file mode 100644 index 0000000..6242900 Binary files /dev/null and b/__pycache__/main.cpython-314.pyc differ diff --git a/bin/Main.class b/bin/Main.class new file mode 100644 index 0000000..853efaa Binary files /dev/null and b/bin/Main.class differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..7f77b05 --- /dev/null +++ b/main.py @@ -0,0 +1,61 @@ +class Sequence: + def __init__(self): + self.sequence = [0] + self.current_idx = 0 + + def add_left(self, value): + self.sequence.insert(self.current_idx, value) + + def add_right(self, value): + self.sequence.insert(self.current_idx + 1, value) + self.current_idx += 1 + + +def task3() -> None: + N = int(input()) + S = input() + + seq = Sequence() + + for i in range(1, N + 1): + ch = S[i - 1] + + if ch == "L": + seq.add_left(i) + elif ch == "R": + seq.add_right(i) + + print(" ".join(map(str, seq.sequence))) + + +def task4() -> None: + n, k = map(int, input().split()) + a = list(map(int, input().split())) + + dp = [[float("-inf")] * (k + 1) for _ in range(n + 1)] + dp[0][0] = 0 + + max_prev = [float("-inf")] * (k + 1) + max_prev[0] = 0 + + for i in range(1, n + 1): + for j in range(k + 1): + if i - 1 >= 0: + dp[i][j] = max(dp[i][j], dp[i - 1][j] + a[i - 1]) + if i - 2 >= 0: + dp[i][j] = max(dp[i][j], dp[i - 2][j] + a[i - 1]) + if j > 0: + dp[i][j] = max(dp[i][j], max_prev[j - 1]) + + for j in range(k + 1): + max_prev[j] = max(max_prev[j], dp[i][j]) + + print(max(dp[n])) + + +def main() -> None: + task4() + + +if __name__ == "__main__": + main()