NC24724. [USACO 2010 Feb S]Chocolate Eating
描述
Here is the complete schedule which turns out to maximize her minimum happiness: Day Wakeup happiness Happiness from eating Bedtime happiness 1 0 10+40 50 2 25 --- 25 3 12 13 25 4 12 22 34 5 17 7 24 The minimum bedtime happiness is 24, which turns out to be the best Bessie can do.
输入描述
* Line 1: Two space separated integers: N and D
* Lines 2..N+1: Line i+1 contains a single integer:
输出描述
* Line 1: A single integer, the highest Bessie's minimum happiness can be over the next D days
* Lines 2..N+1: Line i+1 contains an integer that is the day on which Bessie eats chocolate i
示例1
输入:
5 5 10 40 13 22 7
输出:
24 1 1 3 4 5
C++11(clang++ 3.9) 解法, 执行用时: 34ms, 内存消耗: 1052K, 提交时间: 2019-11-04 10:25:10
#include<cstdio> int n,d,h[50005],ans[50005]; bool chk(long long p){ int al=1,day=0;long long H=0; while(day<d){ while(al<=n&&H<p)H+=h[al],ans[al]=day+1,al++; if(al>n&&H<p)return false; day++;H>>=1; if(day==d)for(int i=al;i<=n;++i)ans[i]=d; }return true; } int main(){ scanf("%d%d",&n,&d); for(int i=1;i<=n;++i)scanf("%d",&h[i]); long long l=0,r=50000000000; while(l<r-1)if(chk(l+r>>1))l=l+r>>1;else r=(l+r>>1)-1; printf("%lld\n",chk(r)?r:l);chk(chk(r)?r:l); for(int i=1;i<=n;++i)printf("%d\n",ans[i]); }