直接dp就好了

每个人肯定会去选最大的,用dp[i]表示选了后i个点时先手-后手的最大值(因为从后往前扫才好转移啊 QwQ~)

dp[i]=max(c[j]-dp[j-1]),(j<=i)

直接维护max值就好了~

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int Mx=1000010;
int n,c[Mx];
long long maxn,dp[Mx];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&c[i]);
    sort(c+1,c+1+n); 
    for(int i=1;i<=n;i++) maxn=max(maxn,c[i]-dp[i-1]),dp[i]=maxn;
    cout<<dp[n]<<endl;
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2021-11-04
  • 2021-09-21
  • 2022-01-17
  • 2021-07-14
  • 2021-05-24
  • 2022-01-05
  • 2021-12-05
猜你喜欢
  • 2021-07-04
  • 2022-01-08
  • 2021-06-17
  • 2021-11-15
  • 2021-08-04
  • 2021-11-02
相关资源
相似解决方案