Kick Veges '
Description
there are N rookie standing in a row, Jason is going to abuse them in order. Abuse of the first rookie needs to spend A[i] point RP, now Jason intends to divide K days to finish these rookie. Jason's total number of RP per day is fixed, in order to make the RP the lowest time not too low to cause the cup, he hopes that the K-day of the most expensive abuse of the RP Day, the cost of RP as little as possible. Ask Jason how many RP he spends on the day the RP spends the most.
Input
The first line is two positive integers n, K.
the second act of this sequence a[i].
Output
A number, the answer to the question.
Sample Input
5 22 1 3 4 5
Sample Output
9
hintn≤100,000, K≤n, ai≤10^9The
first test of summer vacation, brother Siang abuse our problem. I didn't use two points to do a problem before, really!
"He hopes that the K-day abuse of the most expensive RP day, the cost of RP as little as possible," explained, the problem 99% to use the dichotomy of the Sometimes, brother Siang says, don't overlook the 1% chance. In short, brother Siang told us, up posture, code:
#include <cstdio>using namespace Std;int f[100010];int n,k,sum=0,cnt;int check (int rp) {//test up to RP, it takes a few days to finish the CNT =1; int X=RP; for (int i=0;i<n;i++) { if (X>=f[i]) x-=f[i]; else{ cnt++; X=rp-f[i]; } } if (cnt<k) return-1; else if (cnt==k) return 0; else return 1;} int main () { scanf ("%d%d", &n,&k); for (int i=0;i<n;i++) { scanf ("%d", &f[i]); Sum+=f[i]; } int left=0,right=sum,rp= (left+right)/2; int Ha=check (RP); while (ha) {//Find answers approximate position if (ha==-1) right=rp+1; else left=rp-1; rp= (Right+left)/2; Ha=check (RP); } for (int i=left;i<=right;i++) {//Search for answer specific position int Ah=check (i); if (!ah) { printf ("%d\n", I); break; } } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Sdnu 1331.Kick Veges ' SDNU2015 summer Training Team Quiz I "" Dichotomy "" August 3 "