結果
| 問題 | No.1522 Unfairness |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2021-05-30 19:15:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 2,000 ms |
| コード長 | 1,206 bytes |
| 記録 | |
| コンパイル時間 | 787 ms |
| コンパイル使用メモリ | 95,280 KB |
| 実行使用メモリ | 39,008 KB |
| 最終ジャッジ日時 | 2025-11-29 14:45:37 |
| 合計ジャッジ時間 | 2,240 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:46:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
46 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:48:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
48 | for (int i = 0; i < n; i++) scanf("%d", as + i);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 1522.cc: No.1522 Unfairness - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 3000;
const int MAX_M = 3000;
/* typedef */
/* global variables */
int as[MAX_N], dp[MAX_N + 1][MAX_M + 1];
/* subroutines */
inline void setmax(int &a, int b) { if (a < b) a = b; }
/* main */
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", as + i);
sort(as, as + n, greater<int>());
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
int di = (i + 1 < n) ? as[i] - as[i + 1] : 0;
for (int j = 0; j <= m; j++)
if (dp[i][j] >= 0) {
setmax(dp[i + 1][j], dp[i][j]);
if (i + 1 < n && j + di <= m)
setmax(dp[i + 2][j + di], dp[i][j] + as[i]);
}
}
int maxd = 0;
for (int j = 0; j <= m; j++) setmax(maxd, dp[n][j]);
printf("%d\n", maxd);
return 0;
}
tnakao0123