結果

問題 No.5 数字のブロック
ユーザー yycoder
提出日時 2019-12-08 20:54:47
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 196 ms / 5,000 ms
コード長 589 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 29,824 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-31 13:44:02
合計ジャッジ時間 2,784 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>

int sort(int n, int str[]);

int main()
{
	int l, n;
	scanf("%d%d", &l, &n);
	int str[10000];
	int total = 0;
	int count = 0;
	for (int i = 0; i <= n - 1; i++) {
		scanf("%d", &(str[i]));
	}

	sort(n, str);

	for (int k = 0; k <= n - 1; k++) {
		if (total + str[k] <= l){
			total += str[k];
			count++;
		}
	}

	printf("%d", count);



	
	return 0;
}

int sort(int n, int str[])
{
	for (int i = 0; i < n - 2;i++) {
		for (int j = i + 1; j <= n - 1; j++) {
			int a;
			if (str[i] > str[j]) {
				a = str[i];
				str[i] = str[j];
				str[j] = a;
			}
		}
	}
	return 0;
}
0