Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- map<int,int>cntlist1,cntlist2;
- int list1[10005],list2[10005];
- int main()
- {
- int test,i,N,M,minimum;
- scanf("%d",&test);
- while(test--)
- {
- scanf("%d%d",&N,&M);
- for(i=1;i<=N;i++)
- {
- scanf("%d",&list1[i]);
- cntlist1[list1[i]]++;
- }
- for(i=1;i<=M;i++)
- {
- scanf("%d",&list2[i]);
- cntlist2[list2[i]]++;
- }
- minimum = 0;
- for(i=1;i<=N;i++)
- {
- minimum+=abs(cntlist1[list1[i]]-cntlist2[list1[i]]);
- cntlist1[list1[i]] = 0;
- cntlist2[list1[i]] = 0;
- }
- for(i=1;i<=M;i++)
- {
- minimum+=abs(cntlist1[list2[i]]-cntlist2[list2[i]]);
- cntlist1[list2[i]] = 0;
- cntlist2[list2[i]] = 0;
- }
- printf("%d\n",minimum);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment