結果

問題 No.5 数字のブロック
ユーザー Irmystp
提出日時 2014-11-26 21:26:00
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 365 bytes
コンパイル時間 1,505 ms
コンパイル使用メモリ 160,744 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-17 22:03:25
合計ジャッジ時間 1,849 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:10: 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:9:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         scanf("%d", W+x);
      |         ~~~~~^~~~~~~~~~~

ソースコード

diff #

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

int L, N, W[10000];

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