# Bzoj: [Usaco2010]chocolate Eating (Two-point answer)

Source: Internet
Author: User

Because didn't notice long long on the TLE ...

Two minutes and the answer is OK.

------------------------------------------------------------------------------

#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#define REP (i, n) for (int i = 0; i < n; ++i)#define CLR (x, C) memset (x, C, sizeof (x))#define REP (i, n) for (int i = 1; I <= n; ++i)using namespace std;typedef long Long ll;const int MAXN = 50000 + 5;int n, D;int h[MAXN];int ans[MAXN]; bool Jud (ll m) {int cur = 0;ll p = 0;Rep (i, D) {While (P < m) {if (++cur > N) return false;p + = h[cur];}p >>= 1;}return true;}void Get (ll m) {int cur = 0;ll p = 0;Rep (i, D) {While (P < m)p + = h[++cur], ans[cur] = i;p >>= 1;}for (int i = ++cur; I <= n; ++i) ans[i] = D;}int main () {freopen ("test.in", "R", stdin);freopen ("Test.out", "w", stdout);ll L = 0, R = 0;cin >> N >> D;Rep (i, N)scanf ("%d", H + i), R + = h[i];ll Res;While (L <= R) {ll m = (L + R) >> 1;if (Jud (m))res = m, L = m + 1;ElseR = m-1;}get (res);cout << res << "\ n";Rep (i, N) printf ("%d\n", * (ans + i));return 0;}

------------------------------------------------------------------------------

: [Usaco2010]chocolate Eating time limit: ten Sec Memory Limit: 162 MB
Submit: 235 Solved: 90
[Submit] [Status] [Discuss] Description

Bessie received it from Daniel. N blocks of chocolate. She did not want to eat them immediately, but intended to make a plan,

so that in the next in D days, she was able to be as happy as possible. Bessie's happiness index can be measured in an integer, at the start of 0, and when she sleeps every night, the happiness index is halved (odd-down rounded down). Bessie sorted her chocolates according to the time received and insisted on eating chocolate in that order. When she eats The block I chocolate, her happiness index increases the Hj. Can eat any amount of chocolate every day, how to help Bessie reasonable arrangement, so that in D days her minimum happiness index the biggest?

For Example: Suppose a total of five chocolate, Bessie intends to eat them in five days, each piece of chocolate to mention

40 13, 22, 7 f:

 days Wake up Happy index chocolate for eating happy bedtime 12345 025121217 + 4013227 5025253424

The minimum Happiness index in five days is themaximum value of all eating methods.

InputFirst line: Two integers separated by a space: N and D,1≤n. d≤50000the second line to line n+1: The third row represents the happiness index provided by block I chocolate hj,1≤hi≤1000000OutputFirst line: A single integer that represents the maximum value of the minimum Happiness index for Bessie within the next D-Daysecond line to n+1: In line i+l There is an integer that represents the day on which Bessie should eat the block I chocolate. If there are many ways to eat, then the output is sorted by dictionary order and the most up-to-the-way scenarioSample Input55
10
40
13
22
7
Sample Output24
1
1
3
4
5
HINT

Source

Silver

Related Keywords:

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.