Submission #77326949


Source Code Expand

Copy
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
struct hs_s {
int C, V;
};
int cmp_hs(const void* x, const void* y) {
struct hs_s a = *(const struct hs_s*)x, b = *(const struct hs_s*)y;
return (a.V < b.V) - (a.V > b.V);
}
struct info_s {
int V, idx;
};
int cmp_info(const void* x, const void* y) {
struct info_s a = *(const struct info_s*)x, b = *(const struct info_s*)y;
return (a.V < b.V) - (a.V > b.V);
}
int N, K, M;
struct hs_s hs[212345];
struct info_s maxes[212345];
int main(void) {
int i;
uint64_t ans = 0;
if (scanf("%d%d%d", &N, &K, &M) != 3) return 1;
for (i = 1; i <= N; i++) {
if (scanf("%d%d", &hs[i].C, &hs[i].V) != 2) return 1;
if (maxes[hs[i].C].V < hs[i].V) {
maxes[hs[i].C].V = hs[i].V;
maxes[hs[i].C].idx = i;
}
}
qsort(maxes + 1, N, sizeof(*maxes), cmp_info);
for (i = 1; i <= M; i++) {
ans += maxes[i].V;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

struct hs_s {
	int C, V;
};

int cmp_hs(const void* x, const void* y) {
	struct hs_s a = *(const struct hs_s*)x, b = *(const struct hs_s*)y;
	return (a.V < b.V) - (a.V > b.V);
}

struct info_s {
	int V, idx;
};

int cmp_info(const void* x, const void* y) {
	struct info_s a = *(const struct info_s*)x, b = *(const struct info_s*)y;
	return (a.V < b.V) - (a.V > b.V);
}

int N, K, M;
struct hs_s hs[212345];

struct info_s maxes[212345];

int main(void) {
	int i;
	uint64_t ans = 0;
	if (scanf("%d%d%d", &N, &K, &M) != 3) return 1;
	for (i = 1; i <= N; i++) {
		if (scanf("%d%d", &hs[i].C, &hs[i].V) != 2) return 1;
		if (maxes[hs[i].C].V < hs[i].V) {
			maxes[hs[i].C].V = hs[i].V;
			maxes[hs[i].C].idx = i;
		}
	}
	qsort(maxes + 1, N, sizeof(*maxes), cmp_info);
	for (i = 1; i <= M; i++) {
		ans += maxes[i].V;
		hs[maxes[i].idx].V = 0;
	}
	qsort(hs + 1, N, sizeof(*hs), cmp_hs);
	for (i = 1; i <= K - M; i++) {
		ans += hs[i].V;
	}
	printf("%" PRIu64 "\n", ans);
	return 0;
}

/*

1. 色ごとの最大価値のやつを計算
2. それらのうち上位 M 個を取る
3. 残りの中から貪欲に K - M 個を取る

*/

Submission Info

Submission Time
Task C - Variety
User mikecat
Language C23 (GCC 14.2.0)
Score 300
Code Size 1247 Byte
Status AC
Exec Time 62 ms
Memory 6368 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 23
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt
All 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, sample-01.txt, sample-02.txt, sample-03.txt
Case Name Status Exec Time Memory
04.txt AC 0 ms 1576 KiB
05.txt AC 31 ms 6368 KiB
06.txt AC 31 ms 5576 KiB
07.txt AC 28 ms 5628 KiB
08.txt AC 0 ms 1576 KiB
09.txt AC 1 ms 1576 KiB
10.txt AC 1 ms 1780 KiB
11.txt AC 20 ms 3336 KiB
12.txt AC 52 ms 5780 KiB
13.txt AC 57 ms 6088 KiB
14.txt AC 54 ms 5960 KiB
15.txt AC 54 ms 6092 KiB
16.txt AC 55 ms 6216 KiB
17.txt AC 51 ms 6100 KiB
18.txt AC 50 ms 6096 KiB
19.txt AC 52 ms 5968 KiB
20.txt AC 51 ms 6088 KiB
21.txt AC 62 ms 6268 KiB
22.txt AC 27 ms 5652 KiB
23.txt AC 53 ms 5988 KiB
sample-01.txt AC 0 ms 1584 KiB
sample-02.txt AC 0 ms 1580 KiB
sample-03.txt AC 0 ms 1500 KiB


2026-07-11 (Sat)
00:38:54 +09:00