結果

問題 No.5 数字のブロック
ユーザー ninhydrin_
提出日時 2015-04-02 16:32:20
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 304 bytes
コンパイル時間 1,278 ms
コンパイル使用メモリ 161,320 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-17 22:33:10
合計ジャッジ時間 2,170 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
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:11:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |     scanf("%d",&W[i]);
      |     ~~~~~^~~~~~~~~~~~

ソースコード

diff #

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

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