結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
|
| 提出日時 | 2018-04-15 19:08:02 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 706 bytes |
| コンパイル時間 | 216 ms |
| コンパイル使用メモリ | 30,720 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-27 00:04:51 |
| 合計ジャッジ時間 | 2,214 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 WA * 21 |
ソースコード
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
int l, n, *w;
char str[32], *ch;
scanf("%d%*c", &l);
scanf("%d%*c", &n);
w = malloc(sizeof(int)*n);
fgets(str, sizeof(str), stdin);
ch = strtok(str, " \n");
for (int i = 0; i < n; i++) {
if (ch == NULL) break;
else w[i] = atoi(ch);
ch = strtok(NULL, " \n");
}
int tmp;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1; j++) {
if (w[j] > w[j + 1]) {
tmp = w[j];
w[j] = w[j + 1];
w[j + 1] = tmp;
}
}
}
int ans = 0, sum = 0;
for (int i = 0; i < n; i++) {
sum = sum + w[i];
if (l < sum) break;
ans++;
}
printf("%d\n", ans);
return 0;
}