結果

問題 No.798 コレクション
コンテスト
ユーザー vjudge1
提出日時 2026-04-22 14:55:25
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,078 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,752 ms
コンパイル使用メモリ 184,660 KB
実行使用メモリ 35,328 KB
最終ジャッジ日時 2026-04-22 14:55:33
合計ジャッジ時間 3,684 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
#define sc cerr
#define qlog(x) {sc<<#x<<" = "<<(x)<<"\n";}
#define rep(i,l,r) for(ll i=(l);i<=(r);i++)
#define irep(i,l,r) for(ll i=(l);i>=(r);i--)
#define qloga(a,l,r) {sc<<#a<<" : "; rep(I,l,r){sc<<(a)[I]<<" ";}sc<<"\n";}
#define qlogSTL(a) {sc<<#a<<" : "; for(const auto &I:(a)){sc<<(I)<<" ";}sc<<"\n";}
typedef long long ll;
typedef unsigned long long ull;
 
#define int ll
constexpr int N=2e3+10;
int n;
ll f[N][N];
pair<int,int> a[N];
 
void upd(ll &x,ll y){
    x=min(x,y);
}
 
signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
 
    cin>>n;
    rep(i,1,n)cin>>a[i].second>>a[i].first;
    sort(a+1,a+1+n,greater<pair<ll,ll>>());
 
    memset(f,0x3f,sizeof(f));
 
    f[0][0]=0;
    rep(i,0,n)rep(j,0,n){
        int x=a[i+1].second;
        int y=a[i+1].first;
        upd(f[i+1][j],f[i][j]);
        upd(f[i+1][j+1],f[i][j]+x+j*y);
    }
    ll ans=0;
    int cnt=0;
    rep(i,0,n){
        if(cnt>=n){
            ans=f[n][i];
            break;
        }
        cnt++;
        if(i&1)cnt++;
    }
    cout<<ans;
}
0