結果

問題 No.1522 Unfairness
ユーザー tnakao0123tnakao0123
提出日時 2021-05-30 19:15:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,206 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 94,732 KB
実行使用メモリ 38,976 KB
最終ジャッジ日時 2023-08-12 07:29:45
合計ジャッジ時間 2,524 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
38,976 KB
testcase_01 AC 11 ms
38,764 KB
testcase_02 AC 11 ms
38,704 KB
testcase_03 AC 18 ms
38,860 KB
testcase_04 AC 13 ms
38,632 KB
testcase_05 AC 12 ms
38,700 KB
testcase_06 AC 11 ms
38,708 KB
testcase_07 AC 22 ms
38,660 KB
testcase_08 AC 22 ms
38,736 KB
testcase_09 AC 12 ms
38,648 KB
testcase_10 AC 14 ms
38,660 KB
testcase_11 AC 12 ms
38,628 KB
testcase_12 AC 16 ms
38,636 KB
testcase_13 AC 27 ms
38,696 KB
testcase_14 AC 12 ms
38,632 KB
testcase_15 AC 39 ms
38,780 KB
testcase_16 AC 39 ms
38,636 KB
testcase_17 AC 39 ms
38,948 KB
testcase_18 AC 39 ms
38,724 KB
testcase_19 AC 39 ms
38,708 KB
testcase_20 AC 21 ms
38,732 KB
testcase_21 AC 11 ms
38,892 KB
testcase_22 AC 11 ms
38,844 KB
testcase_23 AC 11 ms
38,728 KB
testcase_24 AC 11 ms
38,696 KB
testcase_25 AC 11 ms
38,640 KB
testcase_26 AC 11 ms
38,692 KB
testcase_27 AC 11 ms
38,772 KB
testcase_28 AC 11 ms
38,700 KB
testcase_29 AC 11 ms
38,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1522.cc:  No.1522 Unfairness - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 3000;
const int MAX_M = 3000;

/* typedef */

/* global variables */

int as[MAX_N], dp[MAX_N + 1][MAX_M + 1];

/* subroutines */

inline void setmax(int &a, int b) { if (a < b) a = b; }

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < n; i++) scanf("%d", as + i);
  sort(as, as + n, greater<int>());

  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;

  for (int i = 0; i < n; i++) {
    int di = (i + 1 < n) ? as[i] - as[i + 1] : 0;
    for (int j = 0; j <= m; j++)
      if (dp[i][j] >= 0) {
	setmax(dp[i + 1][j], dp[i][j]);
	if (i + 1 < n && j + di <= m)
	  setmax(dp[i + 2][j + di], dp[i][j] + as[i]);
      }
  }

  int maxd = 0;
  for (int j = 0; j <= m; j++) setmax(maxd, dp[n][j]);

  printf("%d\n", maxd);
  return 0;
}
0