結果

問題 No.1522 Unfairness
ユーザー 👑 NachiaNachia
提出日時 2021-05-13 23:29:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 785 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 81,584 KB
実行使用メモリ 73,908 KB
最終ジャッジ日時 2024-04-29 21:52:51
合計ジャッジ時間 2,944 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
73,856 KB
testcase_01 AC 24 ms
73,792 KB
testcase_02 AC 26 ms
73,856 KB
testcase_03 AC 32 ms
73,704 KB
testcase_04 AC 29 ms
73,816 KB
testcase_05 AC 26 ms
73,720 KB
testcase_06 AC 27 ms
73,892 KB
testcase_07 AC 38 ms
73,728 KB
testcase_08 AC 39 ms
73,696 KB
testcase_09 AC 26 ms
73,828 KB
testcase_10 AC 25 ms
73,768 KB
testcase_11 AC 24 ms
73,904 KB
testcase_12 AC 31 ms
73,752 KB
testcase_13 AC 47 ms
73,844 KB
testcase_14 AC 30 ms
73,856 KB
testcase_15 AC 60 ms
73,856 KB
testcase_16 AC 60 ms
73,804 KB
testcase_17 AC 62 ms
73,908 KB
testcase_18 AC 60 ms
73,728 KB
testcase_19 AC 61 ms
73,856 KB
testcase_20 AC 61 ms
73,856 KB
testcase_21 AC 28 ms
73,684 KB
testcase_22 AC 27 ms
73,752 KB
testcase_23 AC 23 ms
73,692 KB
testcase_24 AC 23 ms
73,840 KB
testcase_25 AC 23 ms
73,840 KB
testcase_26 AC 22 ms
73,824 KB
testcase_27 AC 22 ms
73,728 KB
testcase_28 AC 22 ms
73,660 KB
testcase_29 AC 24 ms
73,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

const ll INF = 1001001001001001001;

ll dp[3001][3001] = {};


int main(){
  int N, M; cin >> N >> M;
  vector<ll> A(N);
  rep(i,N) cin >> A[i];
  sort(A.begin(),A.end());

  rep(i,3001) rep(j,3001) dp[i][j] = -INF;
  rep(s,3001) dp[0][s] = 0;
  rep(i,N+1) rep(s,M+1){
    if(i >= 1) dp[i][s] = max(dp[i][s], dp[i-1][s]);
    if(i >= 2) if(A[i-1]-A[i-2] <= s) dp[i][s] = max(dp[i][s], dp[i-2][s - (A[i-1]-A[i-2])] + A[i-1]);
  }

  cout << dp[N][M] << "\n";
  return 0;
}


struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_instance;

0