Maximize Distinct Elements

Company: Ion_Group_Dev_Test_LDP_Class_2026-Referrals

Difficulty: medium

Problem Statement

Maximize Distinct Elements Problem Description You are given two arrays a and b , each of n integers, and a number k . One operation picks any indices i and j and exchanges a[i] with b[j] . You may perform at most k operations. Report the largest number of distinct values array a can contain afterwards. Input Format The first line contains n . The second line contains n space-separated integers, the array a . The third line contains n space-separated integers, the array b . The fourth line contains k . Output Format Print a single integer: the maximum number of distinct values in a . Constraints 1 <= n <= 1000 (the source paper states 10^5 ; the bound is reduced here so that every graded case fits the platform's input limit) 0 <= k <= 100000 1 <= a[i], b[i] <= 1000000000 Examples Example 1 Input: 5 2 3 3 2 2 1 3 2 4 1 2 Output: 4 Explanation: a holds the values {2, 3} with three surplus copies. From b , the values 1 and 4 are new. Two swaps bring both in, giving [2, 3