Submission #74555194


Source Code Expand

Copy
#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) - (a > b);
}
int N;
int W[312345], P[312345];
int delta[312345];
int main(void) {
int T, tc;
if (scanf("%d", &T) != 1) return 1;
for (tc = 0; tc < T; tc++) {
int i;
long long score = 0;
if (scanf("%d", &N) != 1) return 1;
for (i = 0; i < N; i++) {
if (scanf("%d%d", &W[i], &P[i]) != 2) return 1;
score -= W[i];
delta[i] = W[i] + P[i];
}
qsort(delta, N, sizeof(*delta), cmp);
for (i = 0; i < N; i++) {
score += delta[i];
if (score >= 0) break;
}
printf("%d\n", N - (i + 1));
}
return 0;
}
/*
= P - W
0
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#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) - (a > b);
}

int N;
int W[312345], P[312345];

int delta[312345];

int main(void) {
	int T, tc;
	if (scanf("%d", &T) != 1) return 1;
	for (tc = 0; tc < T; tc++) {
		int i;
		long long score = 0;
		if (scanf("%d", &N) != 1) return 1;
		for (i = 0; i < N; i++) {
			if (scanf("%d%d", &W[i], &P[i]) != 2) return 1;
			score -= W[i];
			delta[i] = W[i] + P[i];
		}
		qsort(delta, N, sizeof(*delta), cmp);
		for (i = 0; i < N; i++) {
			score += delta[i];
			if (score >= 0) break;
		}
		printf("%d\n", N - (i + 1));
	}
	return 0;
}

/*

評価値 = 「ソリを引く」トナカイのPの和 - 「ソリに乗る」トナカイのWの和

これが0以上であればおk

まず、全員「ソリに乗る」 → 評価値 = -(Wの和)

1人「ソリを引く」に回す → 評価値 += P + W

なので、P + W の大きい順に「ソリを引く」に回していけばよい

*/

Submission Info

Submission Time
Task C - Reindeer and Sleigh 2
User mikecat
Language C23 (GCC 14.2.0)
Score 350
Code Size 1089 Byte
Status AC
Exec Time 67 ms
Memory 6340 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 1
AC × 28
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 1580 KiB
01_test_00.txt AC 40 ms 1740 KiB
01_test_01.txt AC 40 ms 1580 KiB
01_test_02.txt AC 42 ms 1632 KiB
01_test_03.txt AC 46 ms 1784 KiB
01_test_04.txt AC 52 ms 1880 KiB
01_test_05.txt AC 57 ms 3264 KiB
01_test_06.txt AC 64 ms 6108 KiB
01_test_07.txt AC 64 ms 6220 KiB
01_test_08.txt AC 64 ms 6316 KiB
01_test_09.txt AC 33 ms 1652 KiB
01_test_10.txt AC 33 ms 1656 KiB
01_test_11.txt AC 34 ms 1652 KiB
01_test_12.txt AC 39 ms 1604 KiB
01_test_13.txt AC 45 ms 1972 KiB
01_test_14.txt AC 48 ms 3184 KiB
01_test_15.txt AC 51 ms 6200 KiB
01_test_16.txt AC 51 ms 6284 KiB
01_test_17.txt AC 52 ms 6236 KiB
01_test_18.txt AC 42 ms 1584 KiB
01_test_19.txt AC 42 ms 1644 KiB
01_test_20.txt AC 43 ms 1544 KiB
01_test_21.txt AC 49 ms 1756 KiB
01_test_22.txt AC 54 ms 1860 KiB
01_test_23.txt AC 46 ms 3056 KiB
01_test_24.txt AC 67 ms 6340 KiB
01_test_25.txt AC 66 ms 6240 KiB
01_test_26.txt AC 66 ms 6284 KiB


2026-03-31 (Tue)
08:54:33 +09:00