Poj 3273 monthly expense (Binary)

Source: Internet
Author: User
// The value of a [I] for the maximum and minimum // days is fixed and cannot be changed. # include <algorithm> # include <string. h> # include <stdio. h> using namespace STD; int n, m; int A [100010]; int judge (int x) {int ans = 1; // It is divided into several groups of int TMP = 0; for (INT I = 0; I <n; I ++) {TMP + = A [I]; If (TMP> X) {TMP = A [I]; // The previous I-1 days less than or equal to m, the previous I-1 days as a group, the day I as the next Group of the first day ans ++ ;}} if (ANS> m) // if the value is greater than m, mid is too small. Return false; return true;} int main () {int I, sum, low; while (~ Scanf ("% d", & N, & M) {sum = 0; Low = 0; for (I = 0; I <n; I ++) {scanf ("% d", & A [I]); sum + = A [I]; If (low <A [I]) Low = A [I];} int L = low; // The minimum boundary is the maximum int r = sum; int mid; while (L <= r) {mid = (L + r)/2; if (Judge (MID) r = mid-1; elsel = Mid + 1;} printf ("% d \ n", L);} 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.