codeforces461a Appleman and Toastman greedy

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.