結果

問題 No.798 コレクション
ユーザー ikdikd
提出日時 2019-03-15 14:03:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 822 bytes
コンパイル時間 787 ms
コンパイル使用メモリ 79,252 KB
実行使用メモリ 34,556 KB
最終ジャッジ日時 2023-09-14 12:14:13
合計ジャッジ時間 2,914 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,504 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 15 ms
16,784 KB
testcase_14 AC 23 ms
25,204 KB
testcase_15 AC 20 ms
21,992 KB
testcase_16 AC 10 ms
11,688 KB
testcase_17 AC 16 ms
17,372 KB
testcase_18 AC 29 ms
32,520 KB
testcase_19 AC 24 ms
26,448 KB
testcase_20 AC 10 ms
12,232 KB
testcase_21 AC 9 ms
10,948 KB
testcase_22 AC 20 ms
21,996 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 31 ms
34,556 KB
testcase_25 AC 31 ms
34,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

void chmin(int64_t &l, int64_t r) {
  if (l > r) l = r;
}

int main() {

  int n;
  cin >> n;
  struct Item {
    int64_t a, b;
  };
  vector<Item> its(n);
  rep(i, n) cin >> its[i].a >> its[i].b;

  sort(its.begin(), its.end(),
       [&](const Item &l, const Item &r) { return l.b > r.b; });
  vector<vector<int64_t>> dp(n + 1, vector<int64_t>(n + 1, 1e18));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      if (j >= 1) chmin(dp[i][j], dp[i - 1][j - 1]);
      if (i - 1 >= j) {
        chmin(dp[i][j],
              dp[i - 1][j] + (its[i - 1].a + its[i - 1].b * (i - j - 1)));
      }
    }
  }

  cout << dp[n][n / 3] << endl;

  return 0;
}
0