The problem of Zhou zhenghu in HUT-XXXX

Source: Internet
Author: User

This question can be directly divided into two parts. Pay attention to the return value of the second part. It is best to manually simulate it in the future.

The Code is as follows:

# Include <cstdlib> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; typedef long int int64; int64 n, m, seq [1000005]; int64 sum (int64 h) {int64 ret = 0; For (INT I = 1; I <= N; ++ I) {If (SEQ [I]> H) {RET + = (SEQ [I]-h) ;}} return ret;} int64 bsearch (int64 L, int64 R) {int64 mid, TOT; while (L <= r) {mid = (L + r)> 1; Tot = sum (MID); If (TOT> m) {L = Mid + 1 ;} else if (TOT <m) {r = mid-1;} else return mid;} return r;} int main () {int64 Max; while (scanf ("% i64d % i64d", & N, & M) = 2) {max =-1; for (INT I = 1; I <= N; ++ I) {scanf ("% i64d", & seq [I]); max = max (max, seq [I]);} printf ("% i64d \ n", bsearch (0, max);} 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.