結果

問題 No.798 コレクション
ユーザー potoooooooopotoooooooo
提出日時 2019-03-21 20:22:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 1,923 ms
コンパイル使用メモリ 180,300 KB
実行使用メモリ 34,724 KB
最終ジャッジ日時 2023-10-19 05:40:22
合計ジャッジ時間 3,179 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 15 ms
17,036 KB
testcase_14 AC 23 ms
25,484 KB
testcase_15 AC 20 ms
22,316 KB
testcase_16 AC 10 ms
12,020 KB
testcase_17 AC 16 ms
17,564 KB
testcase_18 AC 30 ms
32,876 KB
testcase_19 AC 24 ms
26,804 KB
testcase_20 AC 11 ms
12,284 KB
testcase_21 AC 10 ms
11,228 KB
testcase_22 AC 21 ms
22,316 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 31 ms
34,724 KB
testcase_25 AC 31 ms
34,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    vector<pair<long long, long long>> v;
    for (int i = 0; i < n; i++) {
        long long a, b; cin >> a >> b;
        v.emplace_back(b, a);
    }
    sort(v.rbegin(), v.rend());
    vector<vector<long long>> dp(n+1, vector<long long>(n+1, 1e12));
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            // dp[i][j]
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]+v[i].second+v[i].first*(i-j));
            dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]);
        }
    }
    cout << dp[n][n/3] << endl;
    return 0;
}
0