結果
| 問題 | 
                            No.798 コレクション
                             | 
                    
| コンテスト | |
| ユーザー | 
                             koi_kotya
                         | 
                    
| 提出日時 | 2019-03-15 22:16:20 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 37 ms / 2,000 ms | 
| コード長 | 943 bytes | 
| コンパイル時間 | 1,731 ms | 
| コンパイル使用メモリ | 178,916 KB | 
| 実行使用メモリ | 34,688 KB | 
| 最終ジャッジ日時 | 2024-07-01 21:06:27 | 
| 合計ジャッジ時間 | 2,806 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 23 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)
int main() {
    int n;
    cin >> n;
    vector<P> s(n);
    for (int i = 0;i < n;++i) cin >> s[i].second >> s[i].first;
    sort(s.begin(),s.end(),greater<P>());
    vector<vector<ll>> dp(n+1,vector<ll>(n+1,1LL<<50));
    dp[0][0] = 0;
    for (int i = 0;i < n;++i) {
        dp[i+1] = dp[i];
        for (int j = 0;j < n;++j) dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]+s[i].second+s[i].first*j);
    }
    int m = (n-1)/3*2+n%3;
    if (n%3 == 0) m += 2;
    cout << dp[n][m] << endl;
    return 0;
}
            
            
            
        
            
koi_kotya