結果
| 問題 |
No.1522 Unfairness
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2021-05-28 22:44:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 159 ms / 2,000 ms |
| コード長 | 1,354 bytes |
| コンパイル時間 | 1,523 ms |
| コンパイル使用メモリ | 117,476 KB |
| 最終ジャッジ日時 | 2025-01-21 20:13:59 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
const ll INF = 1e18;
ll dp[3005][3005];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
int n, m; cin >> n >> m;
vector<ll> a(n);
for(int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end(), greater<ll>());
ll ans = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j <= m; j++){
// 何もしない
chmax(dp[i+1][j], dp[i][j]);
// a[i], a[i+1]を使う
if(i+1 < n){
int d = a[i]-a[i+1];
if(j+d <= m) chmax(dp[i+2][j+d], dp[i][j]+a[i]);
}
}
}
for(int i = 0; i <= m; i++) chmax(ans, dp[n][i]);
cout << ans << endl;
}
milanis48663220