This page is still under construction.

Parts of this page are still being built. What you see may change.

The Great Wall

Time limit3sMemory limit512 MB

Summary
Each design picks two length-r intervals whose overlap height adds extra cost; find the k-th smallest total wall height over all interval pairs.
Level

Hard8 of 10

Topics
Binary search, Prefix sum, Dynamic programming, Sorting
Solved
No attempts yet

Problem

You have become the emperor of Sinai, a small country. To stop the raids coming across the border you decided to build a great wall there, and you hired W Corp, the only company in the world that builds walls nobody can break through.

W Corp builds every wall from the same pattern. The wall is nn meters long, and each one meter piece is numbered from 11 to nn along its length. Pieces may have different heights. The heights come from three fixed arrays aa, bb, cc of nn elements each, with ai<bi<cia_i < b_i < c_i for every 1≤i≤n1 \le i \le n, and from an integer rr (1≤r<n1 \le r < n). The three arrays and rr are the same for every wall W Corp builds.

A specific design is fixed by two integers xx and yy with 1≤x<y≤n−r+11 \le x < y \le n - r + 1. Take the two ranges [x,x+r−1][x, x+r-1] and [y,y+r−1][y, y+r-1], both inclusive. The height of piece ii is:

  • aia_i if ii lies in neither range,
  • bib_i if ii lies in exactly one of the ranges,
  • cic_i if ii lies in both ranges.

The strength of a wall is the sum of the heights of its nn pieces.

Because aa, bb, cc and rr never change, W Corp hands you a price list of every possible design sorted in non-decreasing order of strength. You pick the kk-th design on that list. Report the strength of the wall you picked.

Input

The first line contains three integers nn, rr, kk (2≤n≤300002 \le n \le 30000, 1≤r<n1 \le r < n, 1≤k≤(n−r)(n−r+1)21 \le k \le \frac{(n-r)(n-r+1)}{2}): the length of the wall, the length of the chosen ranges, and the position on the price list.

The second line contains the nn elements of the array aa (1≤ai≤1061 \le a_i \le 10^6).

The third line contains the nn elements of the array bb (ai<bi≤106a_i < b_i \le 10^6).

The fourth line contains the nn elements of the array cc (bi<ci≤106b_i < c_i \le 10^6).

Output

Print one integer, the strength of the kk-th wall on the price list. Several designs can share the same strength, and the kk-th strength value is the same whichever way those ties are ordered.

Hint

In the first example there are three walls you can build.

  • Choosing x=1x = 1 and y=2y = 2 gives the heights 3 7 5 43\ 7\ 5\ 4 and the strength 1919.
  • Choosing x=1x = 1 and y=3y = 3 gives the heights 3 3 5 53\ 3\ 5\ 5 and the strength 1616.
  • Choosing x=2x = 2 and y=3y = 3 gives the heights 1 3 7 51\ 3\ 7\ 5 and the strength 1616.

Examples2

  1. Example 1

    Input
    4 2 1
    1 2 3 4
    3 3 5 5
    7 7 7 7
    
    Expected output
    16
    
  2. Example 2

    Input
    4 2 3
    1 2 3 4
    3 3 5 5
    7 7 7 7
    
    Expected output
    19