結果

問題 No.798 コレクション
ユーザー pekempeypekempey
提出日時 2019-03-15 21:49:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 797 ms
コンパイル使用メモリ 77,060 KB
実行使用メモリ 34,960 KB
最終ジャッジ日時 2023-09-14 13:25:35
合計ジャッジ時間 2,113 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 12 ms
25,764 KB
testcase_14 AC 16 ms
29,984 KB
testcase_15 AC 15 ms
27,844 KB
testcase_16 AC 10 ms
21,392 KB
testcase_17 AC 12 ms
25,732 KB
testcase_18 AC 19 ms
34,312 KB
testcase_19 AC 17 ms
32,236 KB
testcase_20 AC 10 ms
21,352 KB
testcase_21 AC 9 ms
19,152 KB
testcase_22 AC 14 ms
27,940 KB
testcase_23 AC 1 ms
4,504 KB
testcase_24 AC 20 ms
34,960 KB
testcase_25 AC 20 ms
34,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

long long dp[2001][2020];

void to(long long *x, long long y) {
  *x = min(*x, y);
}

int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  vector<long long> B(N);
  vector<int> P(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
    P[i] = i;
  }
  sort(P.begin(), P.end(), [&](int i, int j) {
    return B[i] > B[j];
  });
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      dp[i][j] = 1e18;
    }
  }
  dp[0][0] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= N; j++) {
      long long c = A[P[i]] + B[P[i]] * j;
      to(&dp[i + 1][j], dp[i][j]);
      to(&dp[i + 1][j + 1], dp[i][j] + c);
    }
  }
  long long ans = 1e18;
  for (int j = 0; j <= N; j++) {
    int k = j / 2;
    if (j + k >= N) {
      ans = min(ans, dp[N][j]);
    }
  }
  cout << ans << endl;
}
0