fork download
  1. #include<bits/stdc++.h>
  2.  
  3. #pragma GCC optimize("O2")
  4. #pragma GCC optimize("O3")
  5. #pragma GCC optimize("Ofast")
  6.  
  7. #define int long long
  8.  
  9. #define pii pair<int,int>
  10. #define ii int,int
  11. #define fi first
  12. #define se second
  13. #define pb push_back
  14. #define lb lower_bound
  15. #define ub upper_bound
  16. #define umap unordered_map
  17. #define BIT(mask, i) ((mask >> i)&1)
  18. #define ALL(c) c.begin(), c.end()
  19.  
  20. using namespace std;
  21.  
  22. mt19937 rd(chrono::high_resolution_clock::now().time_since_epoch().count());
  23. int rand(int l, int r){
  24. return l + rd()*rd()%(r-l+1);
  25. }
  26.  
  27. const int N = 1e6+7;
  28. const int M = 1e3+3;
  29. const int MOD = 1e9+7;
  30. const int inf = 3e18;
  31.  
  32. int n, m, a[100005];
  33.  
  34. signed main(){
  35. ios_base::sync_with_stdio(0);
  36. cin.tie(0);
  37. cout.tie(0);
  38.  
  39. freopen("PRIZE.INP", "r", stdin);
  40. freopen("PRIZE.OUT", "w", stdout);
  41.  
  42. cin >> n >> m;
  43. for(int i = 1; i <= n; i++){
  44. cin >> a[i];
  45. }
  46. map<int,int> mp;
  47. vector<int> v;
  48. for(int i = 1; i <= n; i++){
  49. mp[a[i]]++;
  50. }
  51. // mp[a[i]] là số lần xuất hiện của a[i]
  52. for(auto i : mp){
  53. for(int j = 1; j <= i.second; j++){
  54. v.push_back(i.first);
  55. }
  56. }
  57. reverse(v.begin(), v.end());
  58. int lim = min(m, n);
  59. int ans = 0;
  60. for(int k = 1; k <= lim; k++){
  61. ans = max(ans, k * v[k-1]);
  62. }
  63. cout << ans;
  64. }
  65.  
  66.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty