2
2
id : cf-1914C
3
3
source : CF
4
4
title : Quests
5
- author : Chu Minjae
5
+ author : Chu Minjae, Ankit Seth
6
6
---
7
7
8
8
## Explanation
@@ -39,9 +39,8 @@ int main() {
39
39
for (int z = 1; z < min(n, k); z++) {
40
40
best_second = max(best_second, b[z ]);
41
41
// 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));
45
44
first_total += a[z ];
46
45
}
47
46
@@ -51,4 +50,65 @@ int main() {
51
50
```
52
51
53
52
</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>
54
114
</LanguageSection>
0 commit comments