結果

問題 No.2334 Distinct Cards
ユーザー KeiKei
提出日時 2023-06-02 21:56:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 489 bytes
コンパイル時間 2,331 ms
コンパイル使用メモリ 212,084 KB
実行使用メモリ 8,740 KB
最終ジャッジ日時 2023-08-28 03:22:19
合計ジャッジ時間 4,168 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 69 ms
6,576 KB
testcase_13 AC 72 ms
6,692 KB
testcase_14 AC 71 ms
6,704 KB
testcase_15 AC 74 ms
6,624 KB
testcase_16 AC 70 ms
6,560 KB
testcase_17 AC 85 ms
8,740 KB
testcase_18 AC 85 ms
8,660 KB
testcase_19 AC 80 ms
8,732 KB
testcase_20 AC 28 ms
4,380 KB
testcase_21 AC 27 ms
4,376 KB
testcase_22 AC 28 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	int cnt = 0;
	map<int, int>m;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		m[A]++;
	}
	vector<pair<int, int>>A;
	for (auto w : m) {
		A.emplace_back(w.second, w.first);
	}
	sort(A.begin(), A.end(), greater<pair<int, int>>());
	int M = A.size();
	int ans = 0;
	for (int i = 0; i < M + 1; i++) {
		if (K > 0) {
			ans++;
			K -= A[i].first;
		}
		else {
			cout << ans << endl;
			break;
		}
	}
}
0