結果
問題 | No.5 数字のブロック |
ユーザー |
![]() |
提出日時 | 2014-11-30 20:37:06 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 394 bytes |
コンパイル時間 | 459 ms |
コンパイル使用メモリ | 36,576 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-17 22:07:09 |
合計ジャッジ時間 | 1,346 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | scanf( "%d%d", &L, &N ); | ~~~~~^~~~~~~~~~~~~~~~~~ main.cpp:13:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 13 | scanf( "%d", W+i ); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include<cstdio> #include<algorithm> #define rep(i,a) for(int i=0;i<(a);++i) const int MAX_N = 10000; int L, N, W[MAX_N]; int main() { scanf( "%d%d", &L, &N ); rep( i, N ) scanf( "%d", W+i ); std::sort( W, W+N ); int sum = 0; rep( i, N ) { if( sum+W[i] > L ) { printf( "%d\n", i ); return 0; } sum += W[i]; } printf( "%d\n", N ); return 0; }