結果
問題 | No.798 コレクション |
ユーザー | rtia_iidx |
提出日時 | 2019-03-15 22:21:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 1,336 bytes |
コンパイル時間 | 1,147 ms |
コンパイル使用メモリ | 110,996 KB |
実行使用メモリ | 24,320 KB |
最終ジャッジ日時 | 2024-07-01 21:08:07 |
合計ジャッジ時間 | 2,145 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#include<iostream> #include<vector> #include<algorithm> #include<functional> #include<queue> #include<stack> #include<set> #include<map> #include<unordered_map> #include<climits> #include<cstdlib> #include<cmath> #include<string> #include<iomanip> #include<bitset> using namespace std; #define ll long long int ll const MOD = 1000000007; ll const INF = (long long int)1 << 61; ll mypow(ll x,ll n){ ll ret = 1; while(n > 0){ if(n&1){ ret = (ret*x)%MOD; } x = (x*x)%MOD; n >>= 1; } return ret; } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vector<ll> a(n),b(n); for(int i = 0; i < n; i++){ cin >> a[i] >> b[i]; } vector<pair<ll,ll>> s; for(int i = 0; i < n; i++){ s.push_back(make_pair(b[i],a[i])); } sort(s.begin(),s.end(),greater<pair<ll,ll>>()); ll needs = (n/3)*2 + n%3; vector<vector<ll>> dp(n+1,vector<ll>(needs+1,INF)); dp[0][0] = 0; for(int i = 1; i < n+1; i++){ for(int j = 0; j <= needs; j++){ dp[i][j] = dp[i-1][j]; } for(int j = 1; j <= needs; j++){ dp[i][j] = min(dp[i][j],dp[i-1][j-1] + s[i-1].first * (j-1) + s[i-1].second); } } cout << dp[n][needs] << endl; return 0; }