結果

問題 No.798 コレクション
ユーザー simansiman
提出日時 2022-03-01 19:04:48
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,100 bytes
コンパイル時間 2,051 ms
コンパイル使用メモリ 109,328 KB
実行使用メモリ 34,912 KB
最終ジャッジ日時 2023-09-22 09:25:41
合計ジャッジ時間 4,361 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
34,744 KB
testcase_01 AC 26 ms
34,860 KB
testcase_02 AC 25 ms
34,912 KB
testcase_03 AC 26 ms
34,832 KB
testcase_04 AC 25 ms
34,840 KB
testcase_05 AC 26 ms
34,856 KB
testcase_06 AC 25 ms
34,796 KB
testcase_07 AC 25 ms
34,800 KB
testcase_08 AC 26 ms
34,808 KB
testcase_09 AC 25 ms
34,800 KB
testcase_10 AC 25 ms
34,740 KB
testcase_11 AC 26 ms
34,816 KB
testcase_12 AC 25 ms
34,744 KB
testcase_13 AC 31 ms
34,764 KB
testcase_14 AC 35 ms
34,816 KB
testcase_15 AC 34 ms
34,796 KB
testcase_16 AC 29 ms
34,816 KB
testcase_17 AC 32 ms
34,820 KB
testcase_18 AC 41 ms
34,836 KB
testcase_19 AC 36 ms
34,740 KB
testcase_20 AC 29 ms
34,812 KB
testcase_21 AC 29 ms
34,796 KB
testcase_22 AC 34 ms
34,736 KB
testcase_23 AC 26 ms
34,796 KB
testcase_24 AC 42 ms
34,824 KB
testcase_25 AC 42 ms
34,744 KB
権限があれば一括ダウンロードができます

ソースコード

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