結果
問題 | No.1522 Unfairness |
ユーザー | 👑 Nachia |
提出日時 | 2021-05-13 23:29:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 60 ms / 2,000 ms |
コード長 | 785 bytes |
コンパイル時間 | 750 ms |
コンパイル使用メモリ | 79,216 KB |
最終ジャッジ日時 | 2025-01-21 10:44:17 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) const ll INF = 1001001001001001001; ll dp[3001][3001] = {}; int main(){ int N, M; cin >> N >> M; vector<ll> A(N); rep(i,N) cin >> A[i]; sort(A.begin(),A.end()); rep(i,3001) rep(j,3001) dp[i][j] = -INF; rep(s,3001) dp[0][s] = 0; rep(i,N+1) rep(s,M+1){ if(i >= 1) dp[i][s] = max(dp[i][s], dp[i-1][s]); if(i >= 2) if(A[i-1]-A[i-2] <= s) dp[i][s] = max(dp[i][s], dp[i-2][s - (A[i-1]-A[i-2])] + A[i-1]); } cout << dp[N][M] << "\n"; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;