9/2/25, 10:25 AM Problem - 2096B - Codeforces
|
stdfloat | Logout
HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP RAYAN
PROBLEMS SUBMIT STATUS STANDINGS CUSTOM TEST
Neowise Labs Contest 1 (Codeforces
B. Wonderful Gloves Round 1018, Div. 1 + Div. 2)
Finished
time limit per test: 1 second
memory limit per test: 256 megabytes Practice
You are the proud owner of many colorful gloves, and you keep them in a drawer. Each glove is in one of n colors
numbered 1 to n . Specifically, for each i from 1 to n , you have li left gloves and ri right gloves with color i .
Unfortunately, it's late at night, so you can't see any of your gloves. In other words, you will only know the color → Virtual participation
and the type (left or right) of a glove after you take it out of the drawer.
Virtual contest is a way to take part in past contest,
as close as possible to participation on time. It is
A matching pair of gloves with color i consists of exactly one left glove and one right glove with color i . Find the supported only ICPC mode for virtual contests. If
you've seen these problems, a virtual contest is not
minimum number of gloves you need to take out of the drawer to guarantee that you have at least k matching for you - solve these problems in the archive. If you
pairs of gloves with different colors. just want to solve some problem from a contest, a
virtual contest is not for you - solve this problem in
the archive. Never use someone else's code, read
Formally, find the smallest positive integer x such that: the tutorials or communicate with other person
during a virtual contest.
For any set of x gloves you take out of the drawer, there will always be at least k matching pairs of gloves with Start virtual contest
different colors.
Input → Clone Contest to Mashup
4
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10 ). The
description of the test cases follows.
→ Submit?
5
The first line of each test case contains two integers n , k (1 ≤ k ≤ n ≤ 2 ⋅ 10 ) — the number of different colors,
and the minimum number of required matching pairs of gloves. Language: GNU G++20 13.2 (64 bit, winlibs)
The second line of each test case contains n integers l1 , l2 , … , ln (1 ≤ li ≤ 10
9
) — the number of left gloves Choose
Choose File No file chosen
file:
with color i for each i from 1 to n .
9
Submit
The third line of each test case contains n integers r1 , r2 , … , rn (1 ≤ r i ≤ 10 ) — the number of right gloves
with color i for each i from 1 to n .
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10 .
5
→ Contest materials
Output Announcement (en)
For each test case, output a single integer — the minimum number of gloves you need to take out of the drawer. Tutorial (en)
Example
input Copy
→ CF GetRating
5
3 3 *1100
1 1 1
1 1 1 Show All Tags
1 1
100 Contest Standings
1
3 2
100 1 1
200 1 1
5 2
97 59 50 87 36
95 77 33 13 74
10 6
97 59 50 87 36 95 77 33 13 74
91 14 84 33 54 89 68 34 14 15
output Copy
6
101
303
481
1010
Note
In the first test case, you must take out all of the gloves, so the answer is 6 .
In the second test case, the answer is 101 . If you take out 100 gloves or fewer, then it is possible that all of them
are left gloves, which means you won't have a matching pair of gloves.
In the third test case, the answer is 303 . If you only take out 302 gloves, then one possible scenario is as follows:
Color 1 : 100 left gloves, 200 right gloves
Color 2 : 1 left glove, 0 right gloves
Color 3 : 0 left gloves, 1 right glove
https://codeforces.com/problemset/problem/2096/B 1/2
9/2/25, 10:25 AM Problem - 2096B - Codeforces
You only have multiple matching pairs of gloves with color 1 . So you won't have at least 2 matching pairs of gloves
with different colors.
Codeforces (c) Copyright 2010-2025 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: Sep/02/2025 10:24:36UTC+5 (h1).
Desktop version, switch to mobile version.
Privacy Policy | Terms and Conditions
Supported by
https://codeforces.com/problemset/problem/2096/B 2/2