結果

問題 No.1583 Building Blocks
ユーザー chocoruskchocorusk
提出日時 2021-07-02 22:18:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,388 bytes
コンパイル時間 3,426 ms
コンパイル使用メモリ 190,176 KB
実行使用メモリ 10,748 KB
最終ジャッジ日時 2023-10-12 03:02:48
合計ジャッジ時間 5,237 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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,836 KB
testcase_04 AC 2 ms
5,584 KB
testcase_05 AC 3 ms
4,476 KB
testcase_06 AC 4 ms
7,620 KB
testcase_07 AC 4 ms
7,884 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 5 ms
10,376 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 4 ms
9,656 KB
testcase_13 AC 4 ms
9,604 KB
testcase_14 AC 3 ms
6,104 KB
testcase_15 AC 4 ms
8,532 KB
testcase_16 AC 5 ms
10,364 KB
testcase_17 AC 4 ms
10,068 KB
testcase_18 AC 2 ms
5,736 KB
testcase_19 AC 6 ms
10,536 KB
testcase_20 AC 3 ms
6,332 KB
testcase_21 AC 2 ms
6,192 KB
testcase_22 AC 3 ms
6,424 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 4 ms
9,884 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 4 ms
9,908 KB
testcase_27 AC 3 ms
7,724 KB
testcase_28 AC 5 ms
10,104 KB
testcase_29 AC 3 ms
5,792 KB
testcase_30 AC 3 ms
5,976 KB
testcase_31 AC 4 ms
8,468 KB
testcase_32 AC 3 ms
6,944 KB
testcase_33 AC 5 ms
10,748 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 4 ms
7,992 KB
testcase_36 AC 4 ms
9,604 KB
testcase_37 AC 3 ms
5,668 KB
testcase_38 AC 2 ms
4,352 KB
testcase_39 AC 2 ms
4,352 KB
testcase_40 AC 1 ms
4,352 KB
testcase_41 AC 2 ms
4,352 KB
testcase_42 AC 1 ms
4,352 KB
testcase_43 AC 2 ms
4,352 KB
testcase_44 AC 1 ms
4,348 KB
testcase_45 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n;
    cin>>n;
    ll w[1010], s[1010];
    for(int i=0; i<n; i++){
        cin>>w[i]>>s[i];
    }
    int ind[1010];
    for(int i=0; i<n; i++){
        ind[i]=i;
    }
    sort(ind, ind+n, [&](int i, int j){ return s[i]+w[i]<=s[j]+w[j];});
    ll dp[1010][1010];
    const ll INF=1e18;
    for(int i=0; i<=n; i++) for(int j=0; j<=i; j++) dp[i][j]=INF;
    dp[0][0]=0;
    for(int i=0; i<n; i++){
        int i1=ind[i];
        for(int j=0; j<=i; j++){
            dp[i+1][j]=min(dp[i+1][j], dp[i][j]);
            if(dp[i][j]<=s[i1]){
                dp[i+1][j+1]=min(dp[i+1][j+1], dp[i][j]+w[i1]);
            }
        }
    }
    for(int i=n; i>=0; i--){
        if(dp[n][i]<INF){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}
0