Under construction

Still being built. Things may change

Kimchi

Time limit1sMemory limit256 MB

Summary
Pick bury and take-out days at most D apart to maximize aging days times take-out temperature plus crock value while temperatures fall.
Level

Medium7 of 10

Topics
Dynamic programming, Sliding window, Queue
Solved
No attempts yet

Problem

You ripen kimchi in a crock for NN days, from autumn into winter. You bury the kimchi on one day and take it out on that same day or on a later day.

A kimchi master states the conditions for good kimchi.

  • The longer the aging time, the better the kimchi tastes.
  • Kimchi freezes on cold days, so a higher temperature on the day you take it out makes the kimchi taste better.
  • The value of the crock on the day you bury the kimchi affects the taste.

Written as a formula: if you bury the kimchi on day ii and take it out on day jj (i≤ji \le j), the aging time is j−ij - i, and the aging time may be 00. The taste is then

(j−i)×Tj+Vi(j - i) \times T_j + V_i

where TjT_j is the temperature on day jj and ViV_i is the value of the crock on day ii. Winter is coming, so the temperature only falls, and Ti≥Ti+1T_i \ge T_{i+1} holds for every ii.

Kimchi aged for too long is no good, so the aging time must be at most DD.

Given the temperature and the value of the crock for every day, find the largest taste you can get.

Input

The first line contains the number of days NN and the upper limit on the aging time DD. (1≤D≤N≤1000001 \le D \le N \le 100000)

The second line contains the temperatures T1,T2,…,TNT_1, T_2, \dots, T_N. Each TiT_i is a natural number at most 10910^9, and Ti≥Ti+1T_i \ge T_{i+1} holds for every ii with 1≤i≤N−11 \le i \le N-1.

The third line contains the crock values V1,V2,…,VNV_1, V_2, \dots, V_N. Each ViV_i is a natural number at most 10910^9.

Output

Print the largest taste of the kimchi on one line.

Examples2

  1. Example 1

    Input
    4 4
    23 22 21 20
    20 40 30 50
    
    Expected output
    80
    
  2. Example 2

    Input
    4 1
    23 22 21 20
    20 40 30 50
    
    Expected output
    61