結果

問題 No.1522 Unfairness
ユーザー firiexpfiriexp
提出日時 2021-05-28 21:47:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,277 bytes
コンパイル時間 1,095 ms
コンパイル使用メモリ 106,652 KB
最終ジャッジ日時 2025-01-21 19:58:40
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |     for (auto &&i : A) scanf("%d", &i);
      |                        ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> A(n);
    for (auto &&i : A) scanf("%d", &i);
    sort(A.begin(),A.end(), greater<>());
    auto dp = make_v(n+1, m+1, 0);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= m; ++j) {
            chmax(dp[i+1][j], dp[i][j]);
            if(i+1 < n && j+A[i]-A[i+1] <= m) chmax(dp[i+2][j+A[i]-A[i+1]], dp[i][j]+A[i]);
        }
    }
    cout << *max_element(dp[n].begin(),dp[n].end()) << "\n";
    return 0;
}
0