結果
問題 | No.838 Noelちゃんと星々3 |
ユーザー |
![]() |
提出日時 | 2020-03-29 18:20:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 26 ms / 2,000 ms |
コード長 | 770 bytes |
コンパイル時間 | 2,196 ms |
コンパイル使用メモリ | 199,480 KB |
最終ジャッジ日時 | 2025-01-09 10:51:50 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include<bits/stdc++.h> using lint=long long; using real=long double; void cmn(lint&x,lint y){if(x>y)x=y;} int main(){ std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false); std::cout.setf(std::ios_base::fixed);std::cout.precision(15); lint n;std::cin>>n; std::vector<lint>a(n); for(lint&x:a)std::cin>>x; std::sort(a.begin(),a.end()); lint inf=std::numeric_limits<lint>::max(); std::vector<lint>dp(n+1,inf); dp.at(0)=0; for(lint i=2;i<=n;i++){ for(lint j:{i-2,i-3}){ if(j<0||dp.at(j)==inf)continue; cmn(dp.at(i),dp.at(j) +*std::max_element(a.begin()+j,a.begin()+i) -*std::min_element(a.begin()+j,a.begin()+i)); } } std::cout<<dp.at(n)<<'\n'; }