嘟嘟嘟

只要将每一种字母放一块输出就行了。

证明1:比如 1 2 3 4 5 6,那么这个序列对答案的贡献分别是1和5,2和4 ,3和6……如果重新排列成x x x x o o,会发现对          x x o x x o  答案的贡献不变,所以得证。

证明2:字母ai有x个,那么对答案的最大贡献为x * (x - 1) / 2,重排后能达到理论上界,所以为最优解。   

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-;
const int maxn = 1e5 + ;
inline ll read()
{
ll ans = ;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << ) + (ans << ) + ch - '', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) x = -x, putchar('-');
if(x >= ) write(x / );
putchar(x % + '');
} int n, a[];
char c[maxn]; int main()
{
n = read(); scanf("%s", c);
for(int i = ; i < n; ++i) a[c[i] - 'a']++;
for(int i = ; i <= ; ++i)
if(a[i]) while(a[i]--) putchar(i + 'a');
enter;
return ;
}
05-23 20:03