#P14040. [PAIO 2025] Exhibition

[PAIO 2025] Exhibition

题目描述

You are the curator of a prestigious art exhibition. You have NN paintings, each with two attributes: painting size AiA_i and artistic value BiB_i. You also have MM available frames, each with frame size SjS_j.

You want to select and arrange kk paintings i1,i2,,iki_1, i_2, \dots, i_k and frames j1,j2,,jkj_1, j_2, \dots, j_k for display such that:

  • Each selected painting iti_t is placed in frame jtj_t where the painting size does not exceed the frame size: AitSjtA_{i_t} \le S_{j_t}
  • The painting sizes of selected paintings are non-decreasing in display order: Ai1Ai2AikA_{i_1} \le A_{i_2} \le \dots \le A_{i_k}
  • The artistic values of selected paintings are non-decreasing in display order: Bi1Bi2BikB_{i_1} \le B_{i_2} \le \dots \le B_{i_k}

Find the maximum value of kk for which a valid arrangement exists.

Implementation Details

You need to implement the following function:

int32 max_paintings(int32 N, int32 M, int32[] A, int32[] B, int32[] S)
  • NN: the number of paintings
  • MM: the number of frames
  • AA: array of length NN, where A[i]A[i] is the size of painting ii
  • BB: array of length NN, where B[i]B[i] is the artistic value of painting ii
  • SS: array of length MM, where S[j]S[j] is the size of frame jj
  • The function should return the maximum number of paintings that can be displayed

提示

Examples

The following call max_paintings(3, 3, [1, 2, 3], [1, 2, 4], [2, 3, 5]) should return 3

  • We have 3 paintings with sizes [1,2,3][1, 2, 3] and artistic values [1,2,4][1, 2, 4].
  • We have 3 frames with sizes [2,3,5][2, 3, 5].
  • We can select all 3 paintings: painting 1 (size 1, value 1) in frame 1 (size 2), painting 2 (size 2, value 2) in frame 2 (size 3), and painting 3 (size 3, value 4) in frame 3 (size 5).
  • The sizes are non-decreasing: 1231 \le 2 \le 3 and the artistic values are non-decreasing: 1241 \le 2 \le 4.

The following call max_paintings(4, 3, [1, 3, 2, 4], [3, 2, 3, 5], [3, 6, 4]) should return 3

  • We have 4 paintings with sizes [1,3,2,4][1, 3, 2, 4] and artistic values [3,2,3,5][3, 2, 3, 5].
  • We have 3 frames with sizes [3,6,4][3, 6, 4].
  • We can select paintings with indices 1, 3, and 4: painting 1 (size 1, value 3) in frame 1 (size 3), painting 3 (size 2, value 3) in frame 3 (size 4), and painting 4 (size 4, value 5) in frame 2 (size 6).
  • The sizes are non-decreasing: 1241 \le 2 \le 4 and the artistic values are non-decreasing: 3353 \le 3 \le 5.

The following call max_paintings(4, 3, [1, 3, 2, 4], [3, 2, 3, 5], [1, 1, 4]) should return 2

  • We have 4 paintings with sizes [1,3,2,4][1, 3, 2, 4] and artistic values [3,2,3,5][3, 2, 3, 5].
  • We have 3 frames with sizes [1,1,4][1, 1, 4].
  • We can select painting 1 (size 1, value 3) in frame 1 or 2 (size 1), and painting 4 (size 4, value 5) in frame 3 (size 4).
  • The sizes are non-decreasing: 141 \le 4 and the artistic values are non-decreasing: 353 \le 5.

Sample Grader

The sample grader reads the input in the following format:

  • Line 1: Two integers NN and MM
  • Line 2: NN integers A1,A2,,ANA_1, A_2, \dots, A_N (painting sizes)
  • Line 3: NN integers B1,B2,,BNB_1, B_2, \dots, B_N (artistic values)
  • Line 4: MM integers S1,S2,,SMS_1, S_2, \dots, S_M (frame sizes)

The sample grader calls max_paintings(N, M, A, B, S) and prints the returned value.

Note: The sample grader provided with this problem is just for testing your solution locally. The actual grader used during the contest may be different.

Constraints

  • 1N,M1051 \le N, M \le 10^5
  • 1Ai,Bi,Sj1091 \le A_i, B_i, S_j \le 10^9 for all valid indices

Scoring

  • Subtask 1 (10 points): N,M10N, M \le 10
  • Subtask 2 (20 points): All frame sizes are larger than all painting sizes (Sj>AiS_j > A_i for all i,ji,j)
  • Subtask 3 (20 points): All artistic values are equal (Bi=BjB_i = B_j for all i,ji,j)
  • Subtask 4 (20 points): N,M<2000N, M < 2000
  • Subtask 5 (30 points): No additional constraints