fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27.  
  28.  
  29.  
  30. vector<int> a;
  31.  
  32. vector<int> consistency(int n, int k, int m){
  33.  
  34. unordered_map<int,int> f;
  35. for(int i=0; i<n; i++){
  36. int mod = a[i]%m;
  37.  
  38. f[mod]++;
  39. }
  40.  
  41. int maxi = 0;
  42. int maxMod = 0;
  43.  
  44. for(auto& ff : f){
  45. if(ff.second > maxi){
  46. maxi = ff.second;
  47. maxMod = ff.first;
  48. }
  49. }
  50.  
  51. if(maxi < k) return {};
  52.  
  53. vector<int> ans;
  54. for(int i=0; i<n; i++){
  55. int mod = a[i]%m;
  56. if(mod == maxMod){
  57. ans.push_back(a[i]);
  58. }
  59. if(ans.size() == k) break;
  60. }
  61.  
  62. return ans;
  63. }
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. vector<int> practice(int n, int k, int m){
  80.  
  81.  
  82. }
  83.  
  84.  
  85.  
  86.  
  87.  
  88. void solve() {
  89.  
  90. int n, k, m;
  91. cin>> n >> k >> m;
  92.  
  93. a.resize(n);
  94. for(int i=0; i<n; i++) cin >> a[i];
  95.  
  96. auto ans = consistency(n, k, m);
  97. if(ans.empty()){
  98. cout << "No" << endl;
  99. }
  100. else{
  101. cout << "Yes" << endl;
  102. for(auto& it : ans) cout << it << " "; cout << endl;
  103. }
  104.  
  105.  
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112. int32_t main() {
  113. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  114.  
  115. int t = 1;
  116. while (t--) {
  117. solve();
  118. }
  119.  
  120. return 0;
  121. }
Success #stdin #stdout 0s 5320KB
stdin
4 3 5
2 7 7 7
stdout
Yes
2 7 7