結果

問題 No.5 数字のブロック
ユーザー potato607potato607
提出日時 2020-06-30 01:12:18
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 190 ms / 5,000 ms
コード長 674 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 28,864 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 11:31:14
合計ジャッジ時間 3,027 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 73 ms
4,380 KB
testcase_04 AC 13 ms
4,376 KB
testcase_05 AC 118 ms
4,380 KB
testcase_06 AC 50 ms
4,376 KB
testcase_07 AC 34 ms
4,380 KB
testcase_08 AC 60 ms
4,380 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 117 ms
4,380 KB
testcase_11 AC 29 ms
4,380 KB
testcase_12 AC 80 ms
4,380 KB
testcase_13 AC 103 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 122 ms
4,376 KB
testcase_17 AC 171 ms
4,380 KB
testcase_18 AC 137 ms
4,380 KB
testcase_19 AC 190 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 0 ms
4,380 KB
testcase_24 AC 0 ms
4,376 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 0 ms
4,376 KB
testcase_29 AC 13 ms
4,380 KB
testcase_30 AC 10 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 0 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

void sort(int* a, int len) {

	int i, j;
	int temp = 0;

	for (i = 0;i < len;i++) {
		for (j = i + 1;j < len;j++) {
			if (a[i] > a[j]) {
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}

	return;
}

int main(void) {
	
	int L, N;
	int *a;
	int i, sum,count;

	sum = 0;
	count = 0;

	scanf("%d", &L);
	scanf("%d", &N);

	a = (int*)malloc(sizeof(int) * N);
	if (a == NULL) exit(1);

	for (i = 0;i < N;i++) scanf("%d", &a[i]);

	sort(a, N);

	if (a[0] <= L) {
		while (1) {
			sum += a[count];
			count++;

			if (sum + a[count] > L) break;
			if (count == N) break;
		}
	}

	printf("%d\n", count);

	free(a);

	return 0;
}
0