結果

問題 No.798 コレクション
ユーザー t33ft33f
提出日時 2019-03-17 18:34:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 631 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 77,764 KB
実行使用メモリ 33,304 KB
最終ジャッジ日時 2023-09-21 19:51:10
合計ジャッジ時間 2,528 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 9 ms
24,420 KB
testcase_14 AC 10 ms
28,540 KB
testcase_15 AC 9 ms
26,548 KB
testcase_16 AC 6 ms
20,372 KB
testcase_17 AC 8 ms
24,476 KB
testcase_18 AC 12 ms
32,620 KB
testcase_19 AC 10 ms
30,776 KB
testcase_20 AC 6 ms
20,384 KB
testcase_21 AC 6 ms
18,276 KB
testcase_22 AC 9 ms
26,476 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 12 ms
33,304 KB
testcase_25 AC 12 ms
33,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

long long cost[2001][2001];

int main () {
    int n; cin >> n;
    vector<pair<int, int> > P(n);
    for (auto &p : P) cin >> p.second >> p.first;
    sort(P.rbegin(), P.rend());

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            long long c = cost[i-1][j-1] + P[i-1].second + P[i-1].first * (j-1);
            if (i == j || cost[i-1][j] > c) {
                cost[i][j] = c;
            } else {
                cost[i][j] = cost[i-1][j];
            }
        }
    }
    cout << cost[n][2*(n+1)/3] << endl;
}
0