結果

問題 No.1522 Unfairness
ユーザー tnakao0123tnakao0123
提出日時 2021-05-30 19:12:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,191 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 94,184 KB
実行使用メモリ 39,012 KB
最終ジャッジ日時 2023-08-08 15:15:58
合計ジャッジ時間 3,717 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
38,728 KB
testcase_01 AC 11 ms
38,660 KB
testcase_02 AC 11 ms
38,672 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 12 ms
38,804 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 20 ms
38,948 KB
testcase_21 AC 12 ms
38,796 KB
testcase_22 AC 12 ms
38,736 KB
testcase_23 AC 12 ms
38,788 KB
testcase_24 AC 12 ms
38,712 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 12 ms
38,724 KB
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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)
	  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