Link
Solution
排个序然后dp
Code
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define eps 1e-8
#define maxn 1000010
#define maxe 1000010
#define cl(x) memset(x,0,sizeof(x))
#define rep(i,a,b) for(i=a;i<=b;i++)
#define drep(i,a,b) for(i=a;i>=b;i--)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define de(x) cerr<<#x<<" = "<<x<<endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll read(ll x=0)
{
ll c, f(1);
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
for(;isdigit(c);c=getchar())x=x*10+c-0x30;
return f*x;
}
pll p[maxn];
ll n, f[maxn], pre[maxn], mx, ans[maxn];
int main()
{
ll i;
n = read();
rep(i,1,n)p[i].fi=read(), p[i].se=i;
sort(p+1,p+n+1);
rep(i,3,n)
{
if(f[i-3]>f[mx])mx=i-3;
pre[i]=mx;
if(i<n)f[i]=f[mx]+(p[i+1].fi-p[i].fi);
else f[i]=f[mx];
}
printf("%lld ",p[n].fi-p[1].fi-f[n]);
ll pos = n, tot=0;
while(pos)
{
tot++;
drep(i,pos,pre[pos]+1)ans[p[i].se]=tot;
pos=pre[pos];
}
printf("%lld\n",tot);
rep(i,1,n)printf("%lld ",ans[i]);
return 0;
}