結果

問題 No.798 コレクション
ユーザー Y17Y17
提出日時 2019-03-15 22:58:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 678 bytes
コンパイル時間 2,268 ms
コンパイル使用メモリ 148,276 KB
実行使用メモリ 35,136 KB
最終ジャッジ日時 2023-09-14 14:04:54
合計ジャッジ時間 3,084 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
35,060 KB
testcase_01 AC 12 ms
34,976 KB
testcase_02 AC 11 ms
35,032 KB
testcase_03 AC 12 ms
34,832 KB
testcase_04 AC 11 ms
34,852 KB
testcase_05 AC 11 ms
34,936 KB
testcase_06 AC 11 ms
34,856 KB
testcase_07 AC 11 ms
34,780 KB
testcase_08 AC 11 ms
34,760 KB
testcase_09 AC 11 ms
34,944 KB
testcase_10 AC 11 ms
34,836 KB
testcase_11 AC 11 ms
34,948 KB
testcase_12 AC 11 ms
34,764 KB
testcase_13 AC 21 ms
34,964 KB
testcase_14 AC 26 ms
34,880 KB
testcase_15 AC 24 ms
34,948 KB
testcase_16 AC 18 ms
35,004 KB
testcase_17 AC 21 ms
34,952 KB
testcase_18 AC 31 ms
35,112 KB
testcase_19 AC 27 ms
35,032 KB
testcase_20 AC 18 ms
34,924 KB
testcase_21 AC 17 ms
34,836 KB
testcase_22 AC 24 ms
34,932 KB
testcase_23 AC 11 ms
34,888 KB
testcase_24 AC 31 ms
34,972 KB
testcase_25 AC 31 ms
35,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int n;
pair<long long, long long> p[3000];

long long memo[2010][2010];

long long dp(long long i, int nk, int cnt){
    if(i == n){
        return 0;
    }

    if(memo[i][nk] != -1) return memo[i][nk];

    long long ans = dp(i+1, nk, cnt+1) + p[i].first * cnt + p[i].second;
    if(nk > 0){
        ans = min(ans, dp(i+1, nk-1, cnt));
    }

    return memo[i][nk] = ans;
}

int main(){
    cin >> n;

    for(int i = 0;i < n;i++){
        cin >> p[i].second >> p[i].first;
    }

    sort(p, p+n, greater<pair<long long, long long> >());

    memset(memo, -1, sizeof(memo));

    cout << dp(0, n/3, 0) << endl;

    return 0;
}
0