結果

問題 No.1583 Building Blocks
ユーザー merom686merom686
提出日時 2021-07-02 22:48:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,018 bytes
コンパイル時間 2,352 ms
コンパイル使用メモリ 203,996 KB
実行使用メモリ 7,328 KB
最終ジャッジ日時 2023-10-12 03:04:02
合計ジャッジ時間 3,902 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
5,316 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
5,276 KB
testcase_07 AC 4 ms
5,720 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 6 ms
6,880 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 4 ms
5,912 KB
testcase_13 AC 5 ms
6,472 KB
testcase_14 AC 3 ms
4,896 KB
testcase_15 AC 4 ms
5,636 KB
testcase_16 AC 5 ms
6,168 KB
testcase_17 AC 5 ms
5,948 KB
testcase_18 AC 3 ms
4,352 KB
testcase_19 AC 6 ms
7,328 KB
testcase_20 AC 3 ms
4,816 KB
testcase_21 AC 3 ms
4,748 KB
testcase_22 AC 3 ms
4,940 KB
testcase_23 AC 2 ms
4,352 KB
testcase_24 AC 4 ms
6,384 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 5 ms
6,604 KB
testcase_27 AC 3 ms
4,772 KB
testcase_28 AC 5 ms
6,776 KB
testcase_29 AC 3 ms
4,384 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 4 ms
6,132 KB
testcase_32 AC 3 ms
5,196 KB
testcase_33 AC 6 ms
7,196 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 3 ms
5,380 KB
testcase_36 AC 5 ms
6,520 KB
testcase_37 AC 2 ms
4,408 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 1 ms
4,348 KB
testcase_40 AC 2 ms
4,352 KB
testcase_41 AC 1 ms
4,352 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 1 ms
4,348 KB
testcase_44 AC 1 ms
4,348 KB
testcase_45 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template <class T>
void chmin(T &a, T b) {
    if (b < a) a = b;
}

struct P {
    bool operator<(const P &p) const {
        return w + s < p.w + p.s;
    }
    int w, s;
};

int dp[1001][1001];

int main() {
    int n;
    cin >> n;

    vector<P> p(n);
    for (int i = 0; i < n; i++) {
        int w, s;
        cin >> w >> s;

        p[i] = { w, s };
    }
    sort(p.begin(), p.end());

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] = (int)2.01e9;
        }
    }
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            dp[i + 1][j] = dp[i][j];
        }
        for (int j = 0; j <= i; j++) {
            if (dp[i][j] <= p[i].s) chmin(dp[i + 1][j + 1], dp[i][j] + p[i].w);
        }
    }

    for (int j = n; j >= 0; j--) {
        if (dp[n][j] < (int)2.01e9) {
            cout << j << endl;
            break;
        }
    }

    return 0;
}
0