結果

問題 No.2334 Distinct Cards
ユーザー pseudosodiumpseudosodium
提出日時 2023-06-02 21:34:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,917 bytes
コンパイル時間 2,200 ms
コンパイル使用メモリ 210,308 KB
実行使用メモリ 15,048 KB
最終ジャッジ日時 2023-08-28 02:51:06
合計ジャッジ時間 4,094 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 55 ms
10,696 KB
testcase_13 AC 55 ms
10,716 KB
testcase_14 AC 58 ms
10,696 KB
testcase_15 AC 55 ms
10,720 KB
testcase_16 AC 54 ms
10,632 KB
testcase_17 AC 79 ms
14,584 KB
testcase_18 AC 81 ms
14,944 KB
testcase_19 AC 82 ms
15,048 KB
testcase_20 AC 11 ms
4,380 KB
testcase_21 AC 11 ms
4,380 KB
testcase_22 AC 10 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

template <typename T> istream& operator >> (istream& in, vector<T>& v) { for (auto &it:v) in >> it; return in; }
template <typename T> ostream& operator << (ostream& os, const vector<T>& v) { for (auto it:v) os << it << " "; return os; }
template <typename T1, typename T2> istream& operator >> (istream& in, pair<T1,T2>& p) { in >> p.first >> p.second; return in; }
template <typename T1, typename T2> ostream& operator << (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
// auto operator<<(ostream&o,auto&&v)->enable_if_t<!is_constructible_v<string,decltype(v)>,decltype(o<<*end(v))>{int f=0,u=&o!=&cerr;o<<"["+u;for(auto&&x:v)(f++?o<<", "+u:o)<<x;return o<<"]"+u;}
// auto operator<<(ostream&o,auto&&t)->decltype(o<<get<0>(t)){int f=0,u=&o!=&cerr;o<<"<"+u;apply([&](auto&...x){(((f++?o<<", "+u:o)<<x),...);},t);return o<<">"+u;}
template <typename T1, typename T2> void minn(T1& a, T2 b) { a = min(a,b); }
template <typename T1, typename T2> void maxx(T1& a, T2 b) { a = max(a,b); }

#define int long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sz(v) (int)v.size()
#define deb(x) cerr<<#x<<"="<<x<<'\n';

const int mod = 1e9L + 7;
const int mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795;
const int raw_mango_seed = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(raw_mango_seed);

void solve() {
    int n,k; cin>>n>>k;
    vector<int> a(n); cin>>a;
    map<int,int> m;
    for(int i:a) m[i]++;
    multiset<int> s;
    for(auto &it:m) s.insert(it.second);
    int ans=0;
    while(k>0){
        int x=*s.rbegin(); s.erase(s.find(x));
        k-=x,ans++;
    }
    cout<<ans<<'\n';
}

int32_t main() {
   
    cin.tie(0)->sync_with_stdio(0);
    int tc=1;
    // cin>>tc;
    while(tc--){
        solve();
    }
    return 0;
}
0