#4104093

Solution for 3028 by mikeCAT

Source Code Status Test Cases
    Policy: public     Reviewed: 3    
00:00 sec    1992 KB     1069 bytes    
#include <stdio.h>
#include <stdlib.h>

int cmp(const void* x, const void* y) {
	int a = *(const int*)x, b = *(const int*)y;
	return a > b ? -1 : a < b;
}

int N, M, C;
int l[114514];

int ballNums[114514];
int* balls[114514];

int asumisu;
int mizuhasu[114514];

int main(void) {
	int i;
	int answer = 0;
	if (scanf("%d%d%d", &N, &M, &C) != 3) return 1;
	for (i = 1; i <= C; i++) {
		if (scanf("%d" ,&l[i]) != 1) return 1;
	}
	for (i = 0; i < N; i++) {
		int c, w;
		int* newBalls;
		if (scanf("%d%d", &c, &w) != 2) return 1;
		newBalls = realloc(balls[c], sizeof(*balls[c]) * (ballNums[c] + 1));
		if (newBalls == NULL) return 2;
		newBalls[ballNums[c]++] = w;
		balls[c] = newBalls;
	}
	for (i = 1; i <= C; i++) {
		if (ballNums[i] > 0) {
			int j;
			qsort(balls[i], ballNums[i], sizeof(balls[i]), cmp);
			for (j = 0; j < ballNums[i] && j < l[i]; j++) {
				mizuhasu[asumisu++] = balls[i][j];
			}
		}
	}
	qsort(mizuhasu, asumisu, sizeof(*mizuhasu), cmp);
	for (i = 0; i < M && i < asumisu; i++) {
		answer += mizuhasu[i];
	}
	printf("%d\n", answer);
	return 0;
}

Compile Error Logs:

Status
Judge: 0/73 C CPU: 00:00 sec Memory: 1992 KB Length: 1068 B 2020-01-12 15:03
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: Wrong Answer00:00199225400_sample_01.in
Case #2--26200_sample_02.in
Case #3--180300_sample_03.in
Case #4--180301_small_01.in
Case #5--286401_small_02.in
Case #6--306401_small_03.in
Case #7--159301_small_04.in
Case #8--228301_small_05.in
Case #9--138301_small_06.in
Case #10--596401_small_07.in
Case #11--142201_small_08.in
Case #12--631401_small_09.in
Case #13--373401_small_10.in
Case #14--212301_small_11.in
Case #15--223301_small_12.in
Case #16--273301_small_13.in
Case #17--572401_small_14.in
Case #18--537301_small_15.in
Case #19--307301_small_16.in
Case #20--136401_small_17.in
Case #21--510401_small_18.in
Case #22--156401_small_19.in
Case #23--412401_small_20.in
Case #24--91301_small_21.in
Case #25--111201_small_22.in
Case #26--520401_small_23.in
Case #27--426401_small_24.in
Case #28--408301_small_25.in
Case #29--445401_small_26.in
Case #30--250401_small_27.in
Case #31--174301_small_28.in
Case #32--611301_small_29.in
Case #33--263301_small_30.in
Case #34--9326702_random_01.in
Case #35--11004702_random_02.in
Case #36--10326702_random_03.in
Case #37--8511702_random_04.in
Case #38--8373702_random_05.in
Case #39--10163702_random_06.in
Case #40--11167702_random_07.in
Case #41--9738702_random_08.in
Case #42--11606702_random_09.in
Case #43--7006702_random_10.in
Case #44--11696702_random_11.in
Case #45--11529702_random_12.in
Case #46--11332702_random_13.in
Case #47--9460702_random_14.in
Case #48--9513602_random_15.in
Case #49--9177702_random_16.in
Case #50--9430702_random_17.in
Case #51--9400702_random_18.in
Case #52--8697702_random_19.in
Case #53--11135702_random_20.in
Case #54--1095764903_large_01.in
Case #55--1370118903_large_02.in
Case #56--1172525903_large_03.in
Case #57--1176499903_large_04.in
Case #58--1221143903_large_05.in
Case #59--1046259903_large_06.in
Case #60--1057431903_large_07.in
Case #61--1040576903_large_08.in
Case #62--1161369903_large_09.in
Case #63--1026702903_large_10.in
Case #64--1061315903_large_11.in
Case #65--1312505903_large_12.in
Case #66--1364867903_large_13.in
Case #67--1350749903_large_14.in
Case #68--974018903_large_15.in
Case #69--1161017903_large_16.in
Case #70--1478115903_large_17.in
Case #71--1020022903_large_18.in
Case #72--820555903_large_19.in
Case #73--1212444903_large_20.in
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )