結果

問題 No.798 コレクション
ユーザー siman
提出日時 2022-03-01 19:04:48
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,100 bytes
コンパイル時間 3,379 ms
コンパイル使用メモリ 143,368 KB
実行使用メモリ 34,944 KB
最終ジャッジ日時 2024-07-08 01:34:01
合計ジャッジ時間 5,189 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

struct Item {
  ll a;
  ll b;

  Item(ll a = -1, ll b = -1) {
    this->a = a;
    this->b = b;
  }

  bool operator<(const Item &n) const {
    return b > n.b;
  }
};

int main() {
  int N;
  cin >> N;
  vector<Item> items;

  for (int i = 0; i < N; ++i) {
    ll a, b;
    cin >> a >> b;

    items.push_back(Item(a, b));
  }

  sort(items.begin(), items.end());
  vector<vector<ll>> dp(2010, vector<ll>(2010, LLONG_MAX));
  dp[0][0] = 0;
  int L = N / 3;

  for (int i = 0; i < N; ++i) {
    Item &item = items[i];

    for (int j = 0; j <= i; ++j) {
      int k = i - j;
      if (dp[j][k] == LLONG_MAX) continue;
      if (k > L) continue;

      dp[j + 1][k] = min(dp[j + 1][k], dp[j][k] + item.a + j * item.b);
      dp[j][k + 1] = min(dp[j][k + 1], dp[j][k]);
    }
  }

  int d = N / 3;
  int c = N - d;
  cout << dp[c][d] << endl;

  return 0;
}
0