結果
問題 |
No.1467 Selling Cars
|
ユーザー |
![]() |
提出日時 | 2021-04-02 21:58:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,301 bytes |
コンパイル時間 | 2,501 ms |
コンパイル使用メモリ | 197,928 KB |
最終ジャッジ日時 | 2025-01-20 09:13:19 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 3 TLE * 28 |
ソースコード
#include <bits/stdc++.h> using namespace std; const char newl = '\n'; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);} template<typename T=int> vector<T> read(size_t n){ vector<T> ts(n); for(size_t i=0;i<n;i++) cin>>ts[i]; return ts; } template<typename T> vector<T> sorted(vector<T> vs){ sort(vs.begin(),vs.end()); return vs; } //INSERT ABOVE HERE using ll = long long; const ll INF = 1e18; const int MAX = 2020; ll as[MAX],bs[MAX],dp[MAX]; signed main(){ cin.tie(0); ios::sync_with_stdio(0); int m,n; cin>>m>>n; auto as_=sorted(read(m)); auto bs_=sorted(read(n)); for(int i=0;i<m;i++) as[i]=as_[i]; for(int i=0;i<n;i++) bs[i]=bs_[i]; auto solve=[&](int k)->int{ fill(dp,dp+MAX,INF); dp[0]=0; for(int j=0;j<n;j++){ for(int i=min(m,j*k);i>=0;i--){ if(i+1<=m and dp[i]>=dp[i+1]) break; ll res=0; for(int t=1;t<=k and i+t<=m;t++){ res+=abs(as[i+t-1]-bs[j]); if(dp[i+t]<=dp[i]+res) break; dp[i+t]=dp[i]+res; } } } return dp[m]; }; for(int k=1;k<=m;k++) cout<<solve(k)<<newl; return 0; }