結果

問題 No.798 コレクション
ユーザー ikdikd
提出日時 2019-03-15 10:30:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 79,168 KB
実行使用メモリ 34,668 KB
最終ジャッジ日時 2023-09-11 02:24:04
合計ジャッジ時間 2,250 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,388 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 16 ms
16,980 KB
testcase_14 AC 25 ms
25,188 KB
testcase_15 AC 22 ms
22,068 KB
testcase_16 AC 11 ms
11,804 KB
testcase_17 AC 17 ms
17,264 KB
testcase_18 AC 34 ms
32,568 KB
testcase_19 AC 27 ms
26,720 KB
testcase_20 AC 12 ms
12,076 KB
testcase_21 AC 10 ms
10,892 KB
testcase_22 AC 22 ms
21,944 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 34 ms
34,668 KB
testcase_25 AC 34 ms
34,428 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;
  rep(i, n) {
    rep(j, n) {
      chmin(dp[i + 1][j], dp[i][j] + (its[i].a + its[i].b * (i - j)));
      chmin(dp[i + 1][j + 1], dp[i][j]);
    }
  }

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

  return 0;
}
0