結果

問題 No.1522 Unfairness
ユーザー たたき@競プロ
提出日時 2023-09-02 08:51:20
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 779 bytes
コンパイル時間 5,796 ms
コンパイル使用メモリ 313,712 KB
実行使用メモリ 73,856 KB
最終ジャッジ日時 2024-06-11 15:43:17
合計ジャッジ時間 6,508 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<int,int>;
#define sr string 
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
  int n,m;cin>>n>>m;
  vc<ll>v(n); rep(i,n)cin>>v[i];
  sort(all(v));
  vc dp(n,vc<ll>(m+1,-1e18)); dp[0][0]=0;
  rep(i,n-1){
    dp[i+1]=dp[i];
    ll x=v[i+1]-v[i];
    if(i)rep(j,m+1)if(j+x<=m)dp[i+1][j+x]=max(dp[i+1][j+x],dp[i-1][j]+v[i+1]);
    if(!i)if(x<=m)dp[i+1][x]=v[i+1];
  }
  ll ans=0; rep(i,m+1)ans=max(ans,dp[n-1][i]);
  cout<<ans;
}
  
  
0