Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by hienhayho ( 3 years ago )
#include <bits/stdc++.h>  
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;
typedef vector<pair<long long, long long>> vpll;
typedef vector<pair<int, int>> vpii;
typedef set<int> si;
typedef set<char> sc;
typedef set<string> ss;
typedef set<long long> sll;
typedef map<int, long long> mill;
typedef map<int, string> mis;
typedef map<int, char> mic;
typedef map<int, int> mii;


void solve(){
    int a[100005];
    memset(a, 0, sizeof(a));
    int cnt = 0;
    int cnt_res = 0;
    int odd_count = 0;
    int n, k;
    cin >> n >> k;
    int x;
    for (int i = 1; i <= n; ++i)
    {
    	cin >> x;
    	if (a[x] == 0)
    	{
    		cnt++;
    	}
    	a[x]++;
    }
    if (cnt < k || cnt > 2 * k) cout << "NO" << endl;
    else 
    {
    	for (int i = 1; i <= n; ++i)
    	{
    		if (a[i] >= 2)
    		{
    			cnt_res++;
    		}
    	}
    	if (cnt == k)
    	{
    		if (cnt_res == k) cout << "YES" << endl;
    		else cout << "NO" << endl;
    	}
    	else 
    	{
    		if (cnt_res < (2 * k - cnt)) cout << "NO" << endl;
    		else cout << "YES" << endl;
    	}
    }
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t; cin >> t; for (int i = 1; i <= t; ++i)
    solve();
    
    return 0;
}

 

Revise this Paste

Parent: 125195
Your Name: Code Language: