結果

問題 No.1583 Building Blocks
ユーザー se1ka2se1ka2
提出日時 2021-07-02 22:41:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 656 ms
コンパイル使用メモリ 71,552 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 02:48:35
合計ジャッジ時間 1,899 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll INF = 100000000000000;

int main()
{
    int n;
    cin >> n;
    P p[1003];
    for(int i = 0; i < n; i++){
        ll w, s;
        cin >> w >> s;
        p[i] = P(w + s, s);
    }
    sort(p, p + n);
    ll dp[1003];
    dp[0] = 0;
    for(int j = 1; j <= n; j++) dp[j] = INF;
    for(int i = 0; i < n; i++){
        ll w = p[i].first - p[i].second, s = p[i].second;
        ll d[1003];
        for(int j = 0; j <= n; j++) d[j] = dp[j];
        for(int j = 1; j <= n; j++){
            if(dp[j - 1] <= s) d[j] = min(d[j], dp[j - 1] + w);
        }
        swap(dp, d);
    }
    for(int j = n; j >= 0; j--){
        if(dp[j] < INF){
            cout << j << endl;
            return 0;
        }
    }
}
0