Question 2016: [usac2010] Chocolate eatingtime limit: 10 sec memory limit: 162 MB Description
Bessie received n pieces of chocolate from Daniel. She didn't want to finish them immediately, but planned to make a plan,
So that she can be as happy as possible in the next D days. The happiness index of Bessie can be measured by an integer. The value is 0 at the beginning. When she goes to bed every night, the happiness index will be halved (rounded down when there is an odd number ). Bessie ordered her chocolate according to the receipt time and insisted on eating it in this order. When she eats the I-th chocolate, her happiness index increases by Hj. I can eat any number of chocolates every day. How can I help me arrange it properly so that she has the largest smallest happiness index in D days?
For example, if there are five pieces of chocolate, Bessie intends to finish them in five days.
The values of the provided happiness indexes are 10, 40, 13, 22, and 7, respectively. The best solution is F:
Days |
Happiness index when you get up |
Edible chocolate |
Bedtime Happiness Index |
1 2 3 4 5 |
0 25 12 12 17 |
10 + 40 13 22 7 |
50 25 25 34 24 |
|
|
|
|
The minimum happiness index in the five days is 24, which is the maximum value in all ways.
The first line of input: two integers separated by spaces: N and d, 1 ≤ n. D ≤ 50000 the second row to the n + 1 row: 1st + 1 indicates the happiness index HJ provided by the I chocolate, 1 ≤ Hi ≤ 1000000 output the first row: A single integer, it indicates the maximum value of the smallest happiness index of Bessie in the next d days from the second row to the n + 1: There is an integer in the I + l row, which day should Bessie eat the I chocolate. If there are multiple ways to eat, the sample input55 is the most backward solution after sorting by dictionary
10
40
13
22
7
Sample output24
1
1
3
4
5
Hint Source
Silver
Question
It's a pitfall question again. Well, it's a little bit of detail in the output Qaq wa several times. The idea of this question is to divide the answer into two parts and then judge the correctness.
Code
1 /*Author:WNJXYK*/ 2 #include<cstdio> 3 using namespace std; 4 5 const int Maxn=50000; 6 int n,d; 7 long long cho[Maxn+10]; 8 9 inline bool check(long long x){10 long long sum=0,days=1;11 for (int i=1;i<=n;i++){12 sum+=cho[i];13 while(sum>=x && days<=d){14 sum/=2;15 days++;16 }17 if (days>d) return true;18 }19 return false;20 }21 22 inline void print(long long x){23 long long sum=0,days=1;24 for (int i=1;i<=n;i++){25 sum+=cho[i];26 printf("%d\n",days);27 while(sum>=x && days<d){28 sum/=2;29 days++;30 }31 }32 }33 34 int main(){35 scanf("%d%d",&n,&d);36 for (int i=1;i<=n;i++) scanf("%lld",&cho[i]);37 long long left=0,right=0,mid;38 for (int i=1;i<=n;i++) right+=cho[i];39 while(left<=right){40 mid=(left+right)/2;41 if (check(mid)==false){42 right=mid-1;43 }else{44 left=mid+1;45 }46 }47 printf("%lld\n",left-1);48 print(left-1);49 return 0;50 }View code
Bzoj 2016: [usaco] Chocolate eating