結果
問題 | No.798 コレクション |
ユーザー |
|
提出日時 | 2020-08-05 15:25:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 715 bytes |
コンパイル時間 | 1,031 ms |
コンパイル使用メモリ | 83,204 KB |
最終ジャッジ日時 | 2025-01-12 14:56:43 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> using lint = long long; constexpr lint INF = 1LL << 60; void solve() { int n; std::cin >> n; std::vector<std::pair<lint, lint>> ps(n); for (auto& p : ps) { std::cin >> p.second >> p.first; } std::sort(ps.rbegin(), ps.rend()); std::vector<lint> dp(n + 1, INF); dp[0] = 0; for (auto [b, a] : ps) { for (int i = n; i > 0; --i) { dp[i] = std::min(dp[i], dp[i - 1] + a + b * (i - 1)); } } std::cout << *std::min_element(dp.begin() + n - n / 3, dp.end()) << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }