Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define pb push_back
- int main()
- {
- _test
- {
- int n;
- cin>>n;
- vector<int> a(n);
- for(auto &e: a) cin>>e;
- vector<int> ans;
- multiset<int> mst;
- for(auto e: a)
- mst.insert(e);
- while(mst.size() && *mst.begin()==0)
- {
- int mex = 0;
- while(mst.find(mex) != mst.end())
- {
- mst.erase(mst.find(mex));
- mex++;
- }
- ans.pb(mex);
- }
- for(int i=0; i<mst.size(); i++)
- ans.pb(0);
- cout<<ans.size()<<"\n";
- for(auto e: ans)
- cout<<e<<" ";
- cout<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment