結果

問題 No.1583 Building Blocks
ユーザー rtyurtyu
提出日時 2021-07-09 15:35:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 3,224 ms
コンパイル使用メモリ 70,104 KB
実行使用メモリ 11,340 KB
最終ジャッジ日時 2023-10-12 03:06:03
合計ジャッジ時間 2,411 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 4 ms
7,696 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 5 ms
7,484 KB
testcase_07 AC 5 ms
9,488 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 6 ms
10,476 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 5 ms
9,484 KB
testcase_13 AC 5 ms
9,824 KB
testcase_14 AC 4 ms
7,288 KB
testcase_15 AC 5 ms
9,504 KB
testcase_16 AC 5 ms
9,588 KB
testcase_17 AC 5 ms
9,556 KB
testcase_18 AC 2 ms
4,528 KB
testcase_19 AC 7 ms
11,248 KB
testcase_20 AC 4 ms
7,152 KB
testcase_21 AC 4 ms
7,300 KB
testcase_22 AC 4 ms
7,212 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 5 ms
9,528 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 6 ms
9,864 KB
testcase_27 AC 4 ms
7,176 KB
testcase_28 AC 6 ms
10,296 KB
testcase_29 AC 4 ms
7,020 KB
testcase_30 AC 3 ms
4,348 KB
testcase_31 AC 6 ms
9,500 KB
testcase_32 AC 4 ms
7,416 KB
testcase_33 AC 7 ms
11,340 KB
testcase_34 AC 2 ms
4,352 KB
testcase_35 AC 4 ms
7,472 KB
testcase_36 AC 6 ms
9,732 KB
testcase_37 AC 2 ms
4,576 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 2 ms
4,352 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 2 ms
4,352 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

pair<long long, long long> p[1009];
long long d[1009][1009], inf = 1e18;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i].second >> p[i].first;
        p[i].first += p[i].second;
    }
    sort(p + 1, p + n + 1);
    for (int i = 1; i <= n; i++)
        d[0][i] = inf;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            d[i][j] = d[i - 1][j];
            if (j && d[i - 1][j - 1] + p[i].second <= p[i].first) d[i][j] = min(d[i][j], d[i - 1][j - 1] + p[i].second);
        }
    }
    int ans = 0;
    for (int i = n; i >= 1; i--)
        if (d[n][i] != inf) {
            ans = i;
            break;
        }
    cout << ans << '\n';
    return 0;
}
0