結果
問題 | No.1522 Unfairness |
ユーザー |
![]() |
提出日時 | 2021-05-30 19:45:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 81 ms / 2,000 ms |
コード長 | 1,310 bytes |
コンパイル時間 | 2,469 ms |
コンパイル使用メモリ | 177,572 KB |
実行使用メモリ | 73,856 KB |
最終ジャッジ日時 | 2024-11-19 06:17:08 |
合計ジャッジ時間 | 3,498 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef _DEBUG #include "_DEBUG.hpp" #endif #define int long long const long long inf = 2e18; const int mod = 1e9 + 7; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } template <class T, class V> typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) { t = v; } template <class T, class V> typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v) { for (auto &e : t) fill(e, v); } signed main() { int n, m; cin >> n >> m; vector<int> a(n); cin >> a; sort(a.rbegin(), a.rend()); auto dp = make_vec<int>(n + 1, m + 1); fill(dp, -inf); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= m; j++) { if (i + 2 <= n && j + a[i] - a[i + 1] <= m) dp[i + 2][j + a[i] - a[i + 1]] = max(dp[i + 2][j + a[i] - a[i + 1]], dp[i][j] + a[i]); dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } int ans = *max_element(dp[n].begin(), dp[n].end()); cout << ans << endl; return 0; }