5 1 6 1 2 3 4 6 5 4 2 5 1 6 3 2 1 2 2 2 3 2 4 2 5 2 6
4
3
3
3
2
1
Taking the query $(X, Y) = (2, 2)$ (the second query) as an example:
Initially, the cards in your hand and on the table are as follows:
* In your hand: $(1, 4), (2, 2), (3, 5), (4, 1), (6, 6)$
* On the table: $(5, 3), (7, 2), (8, 2)$
You can achieve holding three cards in your hand, which is the minimum, by performing the following operations:
* Choose card $2$ in your hand with $(2, 2)$ and card $6$ on the table with $(5, 3)$. Remove card $6$ from the table and place card $2$ on the table. Now, the following cards are remaining.
* In your hand: $(1, 4), (3, 5), (4, 1), (6, 6)$
* On the table: $(2, 2), (7, 2), (8, 2)$
* Choose card $4$ in your hand with $(4, 1)$ and card $8$ on the table with $(8, 2)$. Remove card $8$ from the table and place card $4$ on the table. Now, the following cards are remaining.
* In your hand: $(1, 4), (3, 5), (6, 6)$
* On the table: $(2, 2), (7, 2), (4, 1)$10 2 10 12 3 2 4 10 9 5 8 1 6 11 7 3 7 2 6 10 9 1 11 5 8 4 12 2 6 3 3 1 3 1 7 1 12 3 4 3 11 2 1 2 8 1 5
4 5 5 4 2 4 1 6 3 4
20 3 10 18 16 5 12 21 23 14 1 19 17 3 15 13 22 7 4 2 8 9 20 6 11 10 18 1 6 20 9 13 21 17 4 16 15 22 12 14 10 23 2 5 3 19 7 11 8 1 11 1 3 3 19 1 22 2 15 4 9 3 16 1 19 5 21 2 3
13 15 6 11 9 13 8 12 3 15
{
"problem": {
"name": "2D Solitaire",
"description": {
"content": "You are given positive integers $N$ and $K$, and two permutations $A = (A_1, A_2, \\dots, A_{N+K})$ and $B = (B_1, B_2, \\dots, B_{N+K})$ of $(1, 2, \\dots, N+K)$. Process $Q$ queries. For each query, ",
"description_type": "Markdown"
},
"platform": "AtCoder",
"limit": {
"time_limit": 2000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "agc070_d"
},
"statements": [
{
"statement_type": "Markdown",
"content": "You are given positive integers $N$ and $K$, and two permutations $A = (A_1, A_2, \\dots, A_{N+K})$ and $B = (B_1, B_2, \\dots, B_{N+K})$ of $(1, 2, \\dots, N+K)$. \nProcess $Q$ queries.\nFor each query, ...",
"is_translate": false,
"language": "English"
}
]
}