Codeforces Round 916 (Div. 3) 1914C. Quests Solution


 

Problem Link :  https://codeforces.com/problemset/problem/1914/C

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int n , k ; cin >> n >> k ;
  11. vector<int>a(n),b(n),c(n+15);
  12. for ( int i = 0 ; i < n ; i++){
  13. cin >> a[i] ;
  14. }
  15. for ( int i = 0 ; i < n ; i++){
  16. cin >> b[i] ;
  17. }
  18. c[0] = b[0] ;
  19. for (int i = 1 ; i < n ; i++){
  20. c[i] = max(c[i-1],b[i]);
  21. }
  22. int sum = 0 , ans = 0 ;
  23. for ( int i = 0 ; i < min(n,k) ; i++){
  24. sum += a[i] ;
  25. int index = k - ( i + 1 ) ;
  26. int value = sum + index * c[i] ;
  27. ans = max(ans, value ) ;
  28. }
  29. cout << ans <<'\n';
  30. }
  31. return 0 ;
  32. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.