結果

問題 No.798 コレクション
ユーザー betrue12betrue12
提出日時 2019-03-15 21:59:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 910 bytes
コンパイル時間 2,084 ms
コンパイル使用メモリ 202,908 KB
実行使用メモリ 35,032 KB
最終ジャッジ日時 2023-09-14 13:33:24
合計ジャッジ時間 3,630 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 12 ms
23,376 KB
testcase_14 AC 15 ms
29,700 KB
testcase_15 AC 13 ms
27,960 KB
testcase_16 AC 8 ms
16,388 KB
testcase_17 AC 11 ms
23,132 KB
testcase_18 AC 18 ms
34,040 KB
testcase_19 AC 15 ms
30,512 KB
testcase_20 AC 9 ms
16,736 KB
testcase_21 AC 8 ms
15,172 KB
testcase_22 AC 14 ms
27,824 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 18 ms
34,916 KB
testcase_25 AC 18 ms
35,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void chmin(int64_t& a, int64_t b){
    a = min(a, b);
}

int main(){
    int N;
    pair<int, int> BA[2000];
    cin >> N;
    for(int i=0; i<N; i++){
        int a, b;
        cin >> a >> b;
        BA[i] = {b, a};
    }
    sort(BA, BA+N, greater<>());

    int M = 0, get = 0;
    while(get < N){
        M++;
        get++;
        if(M % 2 == 0) get++;
    }

    const int64_t INF = 1e18;
    static int64_t dp[2010][2010];
    for(int i=0; i<=N; i++) for(int j=0; j<=N; j++) dp[i][j] = INF;
    dp[0][0] = 0;
    for(int i=0; i<N; i++){
        int b = BA[i].first, a = BA[i].second;
        for(int j=0; j<=M; j++){
            chmin(dp[i+1][j], dp[i][j]);
            if(j < M){
                int64_t result = dp[i][j] + a + b*j;
                chmin(dp[i+1][j+1], result);
            }
        }
    }

    cout << dp[N][M] << endl;
    return 0;
}
0