結果

問題 No.1522 Unfairness
ユーザー 夜
提出日時 2021-07-20 19:45:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 1,049 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 96,176 KB
実行使用メモリ 74,496 KB
最終ジャッジ日時 2024-04-29 21:59:22
合計ジャッジ時間 2,765 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 34 ms
25,856 KB
testcase_04 AC 12 ms
11,136 KB
testcase_05 AC 9 ms
9,216 KB
testcase_06 AC 12 ms
12,800 KB
testcase_07 AC 45 ms
31,488 KB
testcase_08 AC 55 ms
40,448 KB
testcase_09 AC 8 ms
8,320 KB
testcase_10 AC 22 ms
19,072 KB
testcase_11 AC 10 ms
9,472 KB
testcase_12 AC 23 ms
18,176 KB
testcase_13 AC 70 ms
49,024 KB
testcase_14 AC 8 ms
8,064 KB
testcase_15 AC 118 ms
74,496 KB
testcase_16 AC 118 ms
74,368 KB
testcase_17 AC 117 ms
74,368 KB
testcase_18 AC 117 ms
74,496 KB
testcase_19 AC 117 ms
74,496 KB
testcase_20 AC 120 ms
74,496 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long dp[3030][3030] = {};
long a[3030], r[3030];
int main() {
	long n, m;
	cin >> n >> m;
	for (long i = 1; i <= n; i++) {
		cin >> r[i];
	}
	sort(r + 1, r + n + 1);
	for (int i = 1; i <= n; i++) {
		a[i] = r[n - i + 1];
	}
	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= m; j++) {
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			if (a[i] - a[i + 1] <= m - j) {
				dp[i + 2][j + a[i] - a[i + 1]] = max(dp[i + 2][j + a[i] - a[i + 1]], dp[i][j] + a[i]);
			}
			if (i != n - 1 && a[i] - a[i + 2] <= m - j) {
				dp[i + 3][j + a[i] - a[i + 2]] = max(dp[i + 3][j + a[i] - a[i + 2]], dp[i][j] + a[i]);
			}
		}
	}
	long ans = 0;
	for (int i = 1; i <= n + 1; i++) {
		for (int j = 0; j <= m; j++) {
			ans = max(ans, dp[i][j]);
		}
	}
	cout << ans << endl;
}
0