Skip to content

Commit aa39b30

Browse files
Merge pull request #4562 from Audacity21/master
cf-1914C - Solution codes added in Java and Python
2 parents acfd7cb + 63f8842 commit aa39b30

File tree

1 file changed

+64
-4
lines changed

1 file changed

+64
-4
lines changed

solutions/bronze/cf-1914C.mdx

+64-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
id: cf-1914C
33
source: CF
44
title: Quests
5-
author: Chu Minjae
5+
author: Chu Minjae, Ankit Seth
66
---
77

88
## Explanation
@@ -39,9 +39,8 @@ int main() {
3939
for (int z = 1; z < min(n, k); z++) {
4040
best_second = max(best_second, b[z]);
4141
// compare experience point of completing one more quest or not
42-
if (max_score < first_total + a[z] + best_second * (k - z - 1)) {
43-
max_score = first_total + a[z] + best_second * (k - z - 1);
44-
}
42+
max_score =
43+
max(max_score, first_total + a[z] + best_second * (k - z - 1));
4544
first_total += a[z];
4645
}
4746

@@ -51,4 +50,65 @@ int main() {
5150
```
5251

5352
</CPPSection>
53+
<PySection>
54+
55+
```py
56+
for _ in range(int(input())):
57+
n, k = [int(i) for i in input().split()]
58+
a = [int(i) for i in input().split()]
59+
b = [int(i) for i in input().split()]
60+
61+
best_second = b[0]
62+
first_total = a[0]
63+
max_score = a[0] + best_second * (k - 1)
64+
for z in range(1, min(n, k)):
65+
best_second = max(best_second, b[z])
66+
# compare experience point of completing one more quest or not
67+
max_score = max(max_score, first_total + a[z] + best_second * (k - z - 1))
68+
first_total += a[z]
69+
70+
print(max_score)
71+
```
72+
73+
</PySection>
74+
<JavaSection>
75+
76+
```java
77+
import java.io.*;
78+
import java.util.*;
79+
80+
public class Quests {
81+
public static void main(String[] args) throws IOException {
82+
BufferedReader read =
83+
new BufferedReader(new InputStreamReader(System.in));
84+
int testNum = Integer.parseInt(read.readLine());
85+
for (int t = 0; t < testNum; t++) {
86+
StringTokenizer initial = new StringTokenizer(read.readLine());
87+
int n = Integer.parseInt(initial.nextToken());
88+
int k = Integer.parseInt(initial.nextToken());
89+
int[] a = Arrays.stream(read.readLine().split(" "))
90+
.mapToInt(Integer::parseInt)
91+
.toArray();
92+
int[] b = Arrays.stream(read.readLine().split(" "))
93+
.mapToInt(Integer::parseInt)
94+
.toArray();
95+
96+
int best_second = b[0];
97+
int first_total = a[0];
98+
int max_score = a[0] + best_second * (k - 1);
99+
for (int z = 1; z < Math.min(n, k); z++) {
100+
best_second = Math.max(best_second, b[z]);
101+
// compare experience point of completing one more quest or not
102+
max_score = Math.max(max_score, first_total + a[z] +
103+
best_second * (k - z - 1));
104+
first_total += a[z];
105+
}
106+
107+
System.out.println(max_score);
108+
}
109+
}
110+
}
111+
```
112+
113+
</JavaSection>
54114
</LanguageSection>

0 commit comments

Comments
 (0)