fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define pb push_back
  5. #define all(a) a.begin(), a.end()
  6. #define rep(i, x, n) for (int i = x; i <= n; ++i)
  7. #define inp(a) freopen(a".inp", "r", stdin), freopen(a".out", "w", stdout)
  8.  
  9. const int N = 2e5 + 5;
  10.  
  11.  
  12. int n, k;
  13. int cnt = 0, value = 0;
  14.  
  15. void calc(int i, int remain, vector<int> a){
  16. if (i == n){
  17. map<int, int> mp;
  18.  
  19. for (int x: a) ++mp[x];
  20.  
  21. for (auto [x, c]: mp) if (c > cnt){
  22. cnt = c; value = x;
  23. } else if (c == cnt) value = min(value, x);
  24.  
  25. return;
  26. }
  27.  
  28. rep(add, 0, remain){
  29. a[i] += add;
  30.  
  31. calc(i + 1, remain - add, a);
  32.  
  33. a[i] -= add;
  34. }
  35. }
  36. int main(){
  37. cin.tie(0) -> sync_with_stdio(0);
  38. inp("hopqua");
  39.  
  40. cin >>n >>k;
  41.  
  42. vector<int> a(n);
  43.  
  44. for (int &x: a) cin >>x;
  45.  
  46. calc(0, k, a);
  47.  
  48. cout <<cnt <<' ' <<value;
  49.  
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty