結果

問題 No.798 コレクション
ユーザー ikdikd
提出日時 2019-03-15 10:30:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 79,812 KB
実行使用メモリ 34,560 KB
最終ジャッジ日時 2024-06-28 16:54:01
合計ジャッジ時間 1,789 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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