結果

問題 No.5 数字のブロック
ユーザー naniwha12
提出日時 2019-01-29 00:42:33
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 862 bytes
コンパイル時間 514 ms
コンパイル使用メモリ 54,784 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-07 05:04:43
合計ジャッジ時間 3,027 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 29 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
int l, n;
void
sort(int* a) {
        int t; 
        int i, f = 1; 
        while (f && n >= 0) {
                f = 0; 
                for (i = 0; i < n-1; i++) {
                        if (a[i] > a[i+1]) {
                                a[i]   ^= a[i+1];
                                a[i+1] ^= a[i];
                                a[i]   ^= a[i+1];
                                f = 1;
                        }
                }
        }
        for (i = 0; i < n; i++) cerr << a[i] << " ";
}
int
main() {
        cin >> l >> n;
        int w[n];
        int i;
        for (i = 0; i < n; i++) cin >> w[i];
        sort(w);
        for (i = 0; l >= 0 && i < n; i++)
                l -= w[i];
        if (l = 0) cout << i + 1 << endl;
        else cout << ((i == 1) ? 1 : i-1) << endl;
        return 0;
}
0