Final Exam: unimodal function thirds

Description

There are n bits students, each student participated in all of the m final exam course, we are anxiously waiting for the publication of the results.

I-th position of the students want t i learned days before all results course. If at first t i day, there are at least a score of course not published, he would wait for the final publication of the results of course the results are announced, each wait a day will produce C unpleasant degree.

For the i course, in accordance with the original plan, it will be at the b i publication of the results days.

There are two operations can adjust the time of publication of the results:

  1. I will be responsible course some teachers adjust the curriculum j , after the adjustment program announced time i results a day later, announced the course j time score of one day in advance; each operation to produce A unpleasant degree.
  2. Increase the part of the teacher in charge of discipline i , i discipline which will result in a performance time of day in advance; B each operation produces an unpleasant degree.

The above two operation parameters i, j can be specified, each operation can be executed multiple times, you can reassign the parameters for each execution.

Now I hope you reasonable operation so that the final total of unpleasant degrees and a minimum output of the smallest degrees and can be unpleasant.

Input

The first line of the XYZ three non-negative integer , describe three unpleasant degrees, see [title] Description;
two positive integers second row n, m, respectively, and the number of courses the students;
third row positive integers t i , each student represents a time of hope that the publication of the results; the fourth row of positive integers b i , expressed in terms of the original plan, announced each course of time results.

Output

A line output integer represents the minimum degrees and unpleasant.

Sample Input 1

100 100 2
4 5
5 1 2 3
1 1 2 3 3

Sample Output 1

6

Sample Input 2

3 5 4
5 6
1 1 4 7 8
2 3 3 1 8 2

Sample Output 2

33

Hint

A,B<=1e9,C<=1e16,n,m,bi,ti<=1e5

Just finished doing otaku after completion planned this question to cbx decadent label, so doing more water.

But this kind of one-third of the questions still need to write a solution to a problem to look at the record.

In fact, this question after reading labels mean nothing?

First of all, the ultimate answer is to have an impact on the division of the latest time that subject, we have put this argument as a cost function.

Uh, more obviously, if you put out the results of a few days too late to postpone, then the student can not stand dissatisfaction will be high.

But if you let the teacher to work overtime out of hours too early, then the teacher can not stand dissatisfaction will be high.

So you can smell the taste of unimodal function yet?

Not going to prove that it is indeed a strictly unimodal function. Internet did not. . .

For the time being so understanding. Anyway, there is no counter-example. It is not you play a simulated annealing . First let me continue to go on. . .

So now we can answer the three points, each with a complexity of O (n + m) of the total dissatisfaction statistics, one-third can be.

As for how to statistics, okay? Statistics points out that early discipline can send a total of how many teachers support the other subject is a, then the statistics of how many minutes late disciplines to reach that number of days required for the assistance b.

Then we use a Price for the item A, the price of numerous articles B, b buy pieces minimum cost.

Category talk a little bit is not a problem.

Then for several days have been identified, and then enumerate each student statistics dissatisfaction, it also goes without saying.

Then no problem, right?

 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 #define int long long
 5 int a,b,c,n,m,w[100005],re[100005];
 6 long double Q(int d){
 7     int up=0,down=0;long double fee=0;
 8     for(int i=1;i<=m;++i)if(re[i]>d)down+=re[i]-d;else up+=d-re[i];
 9     if(a<b)fee+=1.0*min(up,down)*a+max(0ll,down-up)*b;else fee=1.0*down*b;
10     for(int i=1;i<=n;++i)fee+=1.0*max(0ll,d-w[i])*c;
11     return fee;
12 }
13 signed main(){
14     scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&n,&m);
15     for(int i=1;i<=n;++i)scanf("%lld",&w[i]);
16     for(int i=1;i<=m;++i)scanf("%lld",&re[i]);
17     int l=1,r=100000,ml,mr,lans,rans;
18     while(l<r-2)if(Q(l+r>>1)<Q((l+r>>1)+1))r=(l+r>>1)+1;else l=l+r>>1;
19     printf("%.0Lf\n",min(Q(l+1),min(Q(l),Q(r))));//printf("%lld %lld\n",l,r);
20 }
But not yet finished

It seems there is a practice, more sloppy.

Because statistics dissatisfaction, this is actually a matter of a sequence, and what predecessor successor prefix, you can use the data structure / STL to achieve what the complexity of the log to count the effect of the answer.

If the operation that is needed to investigate how a few large array b than mid, and how much they are small empathy. After the sort prefix and the lower_bound can be resolved.

And to investigate the t array of mid and larger than their sum, and still prefixes. Then it seems gone, you can actually log?

Not measured, probably I yy?

Then it can be O (1e6) enumerates all the days, and there will be no three-point answer, direct access min on the line. This has not been proven that compared to unimodal function is more reliable?

But I did not play. . .

Oh noteworthy point is the operation of the process so much that C is likely to burst long long, we recommended double.

Because no matter what the data will not answer more than long long, after so much with double compute directly discarded like if, otherwise the checkout.

 

Guess you like

Origin www.cnblogs.com/hzoi-DeepinC/p/11425615.html