結果
| 問題 |
No.1522 Unfairness
|
| コンテスト | |
| ユーザー |
aspi
|
| 提出日時 | 2021-05-04 10:30:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 52 ms / 2,000 ms |
| コード長 | 976 bytes |
| コンパイル時間 | 1,909 ms |
| コンパイル使用メモリ | 204,544 KB |
| 最終ジャッジ日時 | 2025-01-21 06:39:57 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T& xx, T yy) { if (xx < yy) { xx = yy; return true; }return false; }
int main() {
int N, M, ans = 0;
cin >> N >> M;
vector<int>numbers(N);
vector<pair<int, int>>pairs(N - 1);
vector<vector<int>>dp(N + 1, vector<int>(M + 1, 0));
dp[0][0] = 0;
for (int i = 0; i < N; i++)cin >> numbers[i];
sort(numbers.begin(), numbers.end());
reverse(numbers.begin(), numbers.end());
for (int i = 0; i < N - 1; i++) {
pairs[i].first = numbers[i] - numbers[i + 1];
pairs[i].second = numbers[i];
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < M + 1; j++) {
if (i < N - 1 && j + pairs[i].first <= M) {
dp[i + 2][j + pairs[i].first] = dp[i][j] + pairs[i].second;
}
chmax(dp[i + 1][j], dp[i][j]);
}
}
for(int i=0; i < M + 1; i++) chmax(ans, dp[N][i]);
cout << ans << endl;
}
aspi