Skip to content

Instantly share code, notes, and snippets.

@kehanlu
Created December 6, 2018 19:15
Show Gist options
  • Select an option

  • Save kehanlu/7bac226e15b70bdae6681e8e552ae7e6 to your computer and use it in GitHub Desktop.

Select an option

Save kehanlu/7bac226e15b70bdae6681e8e552ae7e6 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
int main(){
int T;
cin >> T;
while(T--){
bool found[200001] = {0};
int n,k;
cin >> n >> k;
int str[n];
for(int i=0;i<n;i++){
cin >> str[i];
}
int rank[n];
for(int i=0;i<n;i++){
int r;
cin >> r;
rank[r-1] = str[i];
}
for(int i=0;i<n;i++){
if(!found[rank[i]]){
cout << rank[i] << " ";
k--;
}
found[rank[i]] = true;
if(k==0) break;
}
for(int i=1;i<=n;i++){
if(!found[i]){
cout << i << " ";
k--;
}
if(k==0)break;
}
cout << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment