結果
問題 | No.798 コレクション |
ユーザー | veqcc |
提出日時 | 2019-03-15 22:28:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 1,001 bytes |
コンパイル時間 | 1,024 ms |
コンパイル使用メモリ | 106,704 KB |
実行使用メモリ | 34,888 KB |
最終ジャッジ日時 | 2024-07-01 21:09:39 |
合計ジャッジ時間 | 2,105 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <string> #include <vector> #include <random> #include <queue> #include <cmath> #include <stack> #include <set> #include <map> typedef long long ll; using namespace std; typedef pair<int, int> P; const ll INF = 1LL << 60; ll dp[2005][2005]; // i番目まで見た時にj個買っている時の金額 int main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; int m = n / 3 * 2 + n % 3; P A[n]; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; A[i] = P(b, a); } sort(A, A+n, greater<P>()); fill(dp[0], dp[n+1], INF); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { dp[i+1][j] = min(dp[i+1][j], dp[i][j]); dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + A[i].second + A[i].first * j); } } cout << dp[n][m] << "\n"; return 0; }