結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
mudbdb
|
| 提出日時 | 2015-06-05 02:27:37 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 484 bytes |
| コンパイル時間 | 198 ms |
| コンパイル使用メモリ | 21,376 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-17 22:48:14 |
| 合計ジャッジ時間 | 1,247 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:11:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | scanf("%d", &L);
| ^~~~~~~~~~~~~~~
main.c:12:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | scanf("%d", &N);
| ^~~~~~~~~~~~~~~
main.c:14:23: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | for (i=0; i<N; i++) scanf("%d", W+i);
| ^~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <stdlib.h>
int cmp(const void* a, const void* b)
{
return (*(int*)a - *(int*)b);
}
int main()
{
int N, L, i;
int *W = NULL;
scanf("%d", &L);
scanf("%d", &N);
W = (int*)malloc(sizeof(int)*N);
for (i=0; i<N; i++) scanf("%d", W+i);
qsort(W, N, sizeof(int), cmp);
int kasan = 0;
for (i=0; i<N; i++) {
kasan += W[i];
if (kasan > L) {
break;
}
}
int ans = i;
printf("%d\n", ans);
free(W);
W = NULL;
return 0;
}
mudbdb