結果
| 問題 |
No.1522 Unfairness
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-02 17:22:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,592 ms / 2,000 ms |
| コード長 | 1,120 bytes |
| コンパイル時間 | 1,921 ms |
| コンパイル使用メモリ | 185,860 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-19 06:17:53 |
| 合計ジャッジ時間 | 12,508 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main(){
int n, m;
cin>>n>>m;
vector<int> a(n);
rep(i, n) cin>>a[i];
sort(a.rbegin(), a.rend());
m++;
vector<int> dp(m), ndp(m);
map<int, int> sp;
sp[0]=INT_MIN/3;
auto upd=[](int &a, int b){ a=max(a, b); };
rep(i, n){
{
rep(j, m) ndp[j]=dp[j];
auto nt=sp.upper_bound(a[i]);
auto it=nt; it--;
rep(j, m){
while(nt!=sp.end() && (nt->first)<=a[i]+j){
it++; nt++;
}
upd(ndp[j], it->second);
}
}
rep(j, m){
int x=j+a[i], y=dp[j]+a[i];
auto rt=sp.upper_bound(x);
auto lt=rt; lt--;
if((lt->second)>=y) continue;
vector<map<int, int>::iterator> dl;
for(; rt!=sp.end() && (rt->second)<=y; rt++){
dl.push_back(rt);
}
for(auto it : dl) sp.erase(it);
sp[x]=y;
}
swap(dp, ndp);
}
cout<<dp[m-1]<<endl;
return 0;
}