Codeforces Round 916 (Div. 3) 1914C. Quests Solution
Problem Link : https://codeforces.com/problemset/problem/1914/C
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n , k ; cin >> n >> k ;
- vector<int>a(n),b(n),c(n+15);
- for ( int i = 0 ; i < n ; i++){
- cin >> a[i] ;
- }
- for ( int i = 0 ; i < n ; i++){
- cin >> b[i] ;
- }
- c[0] = b[0] ;
- for (int i = 1 ; i < n ; i++){
- c[i] = max(c[i-1],b[i]);
- }
- int sum = 0 , ans = 0 ;
- for ( int i = 0 ; i < min(n,k) ; i++){
- sum += a[i] ;
- int index = k - ( i + 1 ) ;
- int value = sum + index * c[i] ;
- ans = max(ans, value ) ;
- }
- cout << ans <<'\n';
- }
- return 0 ;
- }
No comments