#P8286. 「DAOI R1」Ciky

「DAOI R1」Ciky

Background

She is Mine.

Problem Description

In late autumn, leaves are falling everywhere, and Ciky is very happy.

Augen\texttt{Augen} took the kids to the woods and picked up many golden leaves.

All the leaves they picked are regular polygons. Now Augen\texttt{Augen} plans to turn them into specimens, bind them into an album, and give it to Ciky.

To make one specimen, you need to color along the edge of a leaf, and the edge colors of different leaves must be different. Also, each specimen has a corresponding beauty value.

When binding the specimens into an album, the following conditions must be satisfied:

  • The perimeter of the ii-th leaf must not be greater than the perimeter of the (i+1)(i+1)-th leaf.
  • The beauty value of the ii-th leaf must not be greater than the beauty value of the (i+1)(i+1)-th leaf.

Augen\texttt{Augen} has nn pens of different colors, and the ii-th pen can draw a total length of aia_i.

There are mm leaves. The ii-th leaf is a regular kik_i-gon, each side has length bib_i, and its beauty value is cic_i.

More simply, only when kibiajk_i * b_i \leq a_j can the jj-th pen be used to draw the ii-th leaf.

In particular, after a leaf is finished using the ii-th pen, its perimeter becomes aia_i. Each pen can draw at most one leaf.

Augen\texttt{Augen} hopes either to give away more specimens, or to maximize the total beauty value of the specimens made.

Note: The two questions are independent.

Input Format

The first line contains two integers, n,mn, m.

The second line contains nn integers. The ii-th integer denotes aia_i.

The third line contains mm integers. The ii-th integer denotes bib_i.

The fourth line contains mm integers. The ii-th integer denotes cic_i.

The fifth line contains mm integers. The ii-th integer denotes kik_i.

Output Format

There are two lines.

The first line contains one integer, the maximum possible number of specimens in the album.

The second line contains one integer, the maximum possible total beauty value of the specimens made.

Note: The second question does not require putting the specimens into the album.

5 3
9 7 2 5 6
1 2 1
2 6 8
3 3 4
3
16

Hint

Sample Explanation

For the first question, use the 44-th pen to draw the 11-st leaf, the 55-th pen to draw the 22-nd leaf, and the 11-st pen to draw the 33-rd leaf. The resulting perimeters are 5,6,95, 6, 9, so you can draw 33 leaves.

For the second question, you can use the same method. The total beauty value is 2+6+8=162 + 6 + 8 = 16.

Constraints

This problem uses bundled testdata.

Subtask nn mm Score
00 10\le 10 1010
11 103\le 10^3 2020
22 106\le 10^6 106\leq 10^6 7070

For 100%100\% of the testdata, 1n,m1061 \leq n, m \leq 10^6, 3ki1063 \leq k_i \leq 10^6, 1ai1091 \leq a_i \leq 10^9, 1bi,ci1061 \leq b_i, c_i \leq 10^6.

Translated by ChatGPT 5