upd
This commit is contained in:
41
Main.java
Normal file
41
Main.java
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
__pycache__/main.cpython-314.pyc
Normal file
BIN
__pycache__/main.cpython-314.pyc
Normal file
Binary file not shown.
BIN
bin/Main.class
Normal file
BIN
bin/Main.class
Normal file
Binary file not shown.
61
main.py
Normal file
61
main.py
Normal file
@@ -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()
|
||||||
Reference in New Issue
Block a user