The main idea is appleman each time to Toastman to his NI number split into two parts and then back to Toastman, if ni = = 1 is directly discarded not split, and Toastman will each get the number of MI accumulated as a fraction, At the initial time, Toastman directly obtains n number, asks Toastman to obtain the highest score which finally can attain.
This simple greedy, appleman each time the split, the smallest number as part of the rest as another part, so that the larger number as many as possible to participate in the accumulation.
#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