結果

問題 No.798 コレクション
ユーザー t33f
提出日時 2019-03-17 18:34:22
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 631 bytes
コンパイル時間 995 ms
コンパイル使用メモリ 77,392 KB
実行使用メモリ 26,112 KB
最終ジャッジ日時 2024-07-07 13:23:55
合計ジャッジ時間 2,027 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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