The main idea is appleman each time toastman to his NI number split into two parts and then back to Toastman, if ni = = 1 is directly discarded not split. The Toastman will accumulate each MI number as a fraction, the initial toastman directly get n number, ask Toastman the last can get the highest score is how much.
This simple greedy, appleman every time the split. Use the smallest number as part of the rest as a separate part, which allows the larger number to participate and accumulate as many times as possible.
#include <stdlib.h> #include <stdio.h> #include <algorithm>int values[500001];long long sums[500001] ; int compp (const void* A1, const void* A2) {return * ((int*) A2)-* ((int*) A1);} int main () {#ifdef _debugfreopen ("E:\\in.txt", "R", stdin), #endif//_debugint n;scanf ("%d", &n), for (int i = 0; i < n;i++) {scanf ("%d", &values[i]);} Qsort (values, n, sizeof (int), COMPP), sums[0] = values[0];for (int i = 1; i < n;i++) {Sums[i] = Sums[i-1] + values[i];} Long Long res = sums[n-1];for (int i = n-1; I >= 1;i--) {res + = Sums[i];} printf ("%i64d\n", res); return 0;}
codeforces461a Appleman and Toastman greedy