結果
問題 | No.2334 Distinct Cards |
ユーザー |
|
提出日時 | 2023-06-02 22:17:54 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 80 ms / 2,000 ms |
コード長 | 871 bytes |
コンパイル時間 | 4,870 ms |
コンパイル使用メモリ | 265,964 KB |
実行使用メモリ | 8,704 KB |
最終ジャッジ日時 | 2024-12-28 18:57:46 |
合計ジャッジ時間 | 5,752 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h>#define rep(i, n) for (int i = 0; i < (n); ++i)using namespace std;using P = pair<int, int>;int main() {int n, k;cin >> n >> k;vector<int> a(n);rep(i, n) cin >> a[i];rep(i, n) a[i]--;vector<int> cnt(n);rep(i, n) cnt[a[i]]++;map<int, int> mp;set<int> s;rep(i, n) {if (s.count(a[i])) continue;mp[cnt[a[i]]]++;s.insert(a[i]);}vector<P> ps;for (auto [c, y] : mp) {ps.emplace_back(c, y);}sort(ps.rbegin(), ps.rend());int ans = 0;for (auto [c, y] : ps) {while (y) {ans++;int nc = c;k -= nc;if (k <= 0) {cout << ans << '\n';return 0;}y--;}}return 0;}