結果
| 問題 | 
                            No.798 コレクション
                             | 
                    
| コンテスト | |
| ユーザー | 
                             NOSS
                         | 
                    
| 提出日時 | 2019-03-16 00:45:47 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 27 ms / 2,000 ms | 
| コード長 | 1,081 bytes | 
| コンパイル時間 | 1,722 ms | 
| コンパイル使用メモリ | 174,312 KB | 
| 実行使用メモリ | 34,816 KB | 
| 最終ジャッジ日時 | 2024-07-01 22:12:01 | 
| 合計ジャッジ時間 | 2,781 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 23 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<int ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()
int n, m;
ll dp[2005][2005];
vector<P> v;
int main() {
    cin >> n;
    m = n/3;
    REP(i,n){
        ll a, b;
        cin >> a >> b;
        v.push_back({b,a});
    }
    SORT(v);
    reverse(ALL(v));
    REP(i,n+1) fill(dp[i], dp[i]+n+1, LLINF/3);
    dp[0][0] = 0;
    for(int i=0;i<n;i++){
        ll a = v[i].second, b = v[i].first;
        dp[i+1][0] = dp[i][0] + b*i + a;
        for(int j=1;j<=m;j++){
            dp[i+1][j] = min(dp[i][j] + b*(i-j) + a, dp[i][j-1]);
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}
            
            
            
        
            
NOSS