Sgu 180 greedy

Source: Internet
Author: User

I have to say that I did not understand the meaning of the question. I can only read the report to understand the question. The general idea is that there are n chains and each chain has L rings, you can remove a chain from it in one minute, and then connect the two chains. Ask the minimum time to connect these chains into one chain. Remove the shortest chain and start from the longest chain.

# Include <cstdio> # include <iostream> # include <cstring> # include <algorithm> using namespace STD; int main () {// freopen ("in.txt ", "r", stdin); int n, a [110], ANS = 0; CIN> N; For (INT I = 0; I <n; I ++) cin> A [I]; sort (A, A + n); For (INT I = 0; I <n; I ++) {if (I> 0) A [I] + = A [I-1]; if (a [I] = n-1-i-1) {ans = n-1-i-1; break;} else if (a [I]> = n-1-i) {ans = n-i-1; break; }}cout <ans <Endl; return 0 ;}

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.