Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define boAshraf ios_base::sync_with_stdio(false); cin.tie(NULL);
- #define ll long long
- #define sz(s) (int)(s).size()
- #define all(s) (s).begin(),(s).end()
- using namespace std;
- void File();
- void sol();
- int main() {
- boAshraf
- File();
- int t = 1;
- cin >> t;
- while (t--) {
- sol();
- }
- return 0;
- }
- void sol() {
- int n;
- cin>>n;
- map<int,int>mp;
- vector<int>v;
- int ans=1e9;
- for (int i = 0; i < n; ++i) {
- int x;cin>>x;
- mp[x]++;
- v.emplace_back(x);
- }
- sort(all(v));
- int cnt=0;
- for(int st=1;st<=2*n;st++){
- if(mp[st])cnt+=mp[st]-1;
- else cnt++;
- auto idx= upper_bound(all(v),st);
- int temp=cnt;
- if(idx!=v.end()){
- int rem=idx-v.begin();
- rem=n-rem;
- temp+=rem;
- }
- ans=min(ans,temp);
- }
- cout<<ans<<'\n';
- }
- void File() {
- // #ifndef ONLINE_JUDGE
- freopen("task.in", "r", stdin);
- // freopen("output.txt", "w", stdout);
- // #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment