ZOJ 3778 Talented Chef simulation [wish tomorrow the Provincial race sailing, Zjsu_bloom will WIN:)

Source: Internet
Author: User

It means to give you n-course, I need an Ai step to finish the course.

How many times do you have to do it at least once each time you can complete one step for M-course?

This is definitely not a violent writing, the province last year when the game was not written out of the problem, today, and then the idea of a rationale.

First of all, we need to be clear

1. N <= m, then the obvious answer is Max (A[i])

2. n > M

① at this point we are not difficult to find this phenomenon, if sum (A[i]) can be divided by M, then we may just need (sum/m) times to complete

An example: n = 3, M = 2

A[1] = 1, a[2] = 2, a[3] = 3

  

② if sum (A[i]) cannot be divisible by M, then only 1 can be added on the basis of ①.

Of course, here should not forget, in the answer output, to ensure that the answer >= Max (A[i]), otherwise there will be a a[i] multiple subtraction operation

Paste the Source Code:

1#include <cstdio>2#include <iostream>3#include <string>4#include <cstring>5#include <stack>6#include <queue>7#include <vector>8#include <cstdlib>9#include <algorithm>Ten  One using namespacestd; A  - inta[60000]; - intN, M; the  - intMain () { -     intI, J, K, u, V, t; -  +CIN >>T; -      while(t--) { +CIN >> N >>m; A         intsum =0; at         intMAX =0; -          for(i =0; I < n; ++i) { -CIN >>A[i]; -Sum + =A[i]; -MAX =Max (max, a[i]); -         } in  -         if(N <=m) { tocout << MAX <<Endl; +             Continue; -         } the  *         intcur = SUM/m; $         if(sum% m! =0)   ++cur;Panax Notoginseng  -Cur =max (cur, max); the  +cout << cur <<Endl; A     } the  +     return 0; -}

ZOJ 3778 Talented Chef simulation [wish tomorrow the Provincial race sailing, Zjsu_bloom will WIN:)

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.