結果

問題 No.5 数字のブロック
ユーザー ninhydrin_
提出日時 2015-04-02 16:20:53
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 336 bytes
コンパイル時間 2,136 ms
コンパイル使用メモリ 160,428 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-03 23:30:03
合計ジャッジ時間 2,220 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24 WA * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:4:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
    4 | main()
      | ^~~~
main.cpp: In function ‘int main()’:
main.cpp:7:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |   scanf("%d%d",&L,&N);
      |   ~~~~~^~~~~~~~~~~~~~
main.cpp:10:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |     scanf("%d",&W[i]);
      |     ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

main()
{
  int L,N;
  scanf("%d%d",&L,&N);
  int W[N];
  for (int i = 0; i < N; ++i) { 
    scanf("%d",&W[i]);        
  }
  int count=0;
  sort(W,W+N);
  for (int i = 0; i < N; ++i) { 
    if(L<W[i]){printf("%d\n",count);break;}
    else {L-=W[i];count++;}        
  }
  return 0;
  
}  
0