結果

問題 No.1522 Unfairness
ユーザー spipipikespipipike
提出日時 2021-06-02 17:22:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,672 ms / 2,000 ms
コード長 1,120 bytes
コンパイル時間 1,900 ms
コンパイル使用メモリ 184,728 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 21:59:19
合計ジャッジ時間 12,771 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 150 ms
5,376 KB
testcase_04 AC 37 ms
5,376 KB
testcase_05 AC 16 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 314 ms
5,376 KB
testcase_08 AC 562 ms
5,376 KB
testcase_09 AC 8 ms
5,376 KB
testcase_10 AC 124 ms
5,376 KB
testcase_11 AC 16 ms
5,376 KB
testcase_12 AC 69 ms
5,376 KB
testcase_13 AC 697 ms
5,376 KB
testcase_14 AC 11 ms
5,376 KB
testcase_15 AC 1,672 ms
5,376 KB
testcase_16 AC 1,571 ms
5,376 KB
testcase_17 AC 1,559 ms
5,376 KB
testcase_18 AC 1,541 ms
5,376 KB
testcase_19 AC 1,576 ms
5,376 KB
testcase_20 AC 75 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
 
0