結果

問題 No.5 数字のブロック
ユーザー mell1
提出日時 2018-11-22 18:26:22
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 189 ms / 5,000 ms
コード長 681 bytes
コンパイル時間 628 ms
コンパイル使用メモリ 55,344 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-18 12:43:45
合計ジャッジ時間 2,882 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#define N 10000
using namespace std;
void sort(int n, int a[]) {
    int i, j, tmp;
    for (i=0; i<=n-2; i++) {
        for (j=i+1; j<n; j++) {
            if (a[i] > a[j]) {
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            }
        }
    }
}
int main() {
    int i, width, n, a[N], sum=0, count=0;
    cin >> width >> n;
    for (i=0; i<n; i++) {
        cin >> a[i];
    }
    sort(n, a);
    while (sum <= width) {
        sum += a[count];
        count++;
        if (count == n) break;
    }
    if (count != n || sum > width) sum -= a[--count];
    cout << count << endl;
    return 0;
}
0