ZCC loves codefires
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 790 accepted submission (s): 420
Problem description though ZCC has extends fans, ZCC himself is a crazy fan of a coder, called "memsetfan ".
It was on codefires (CF), an online competitive programming site, that ZCC knew memsettings, and immediately became his fan.
But why?
Because memset137 can solve all problem in rounds, without extends submissions; his estimation of time to solve certain problem is so accurate, that he can surely get an accepted the second he has predicted. he soon became IgM, the best title of codefires. besides, he is famous for his coding speed and the achievement in the field of data structures.
After become IgM, memsetincluhas a new goal: he wants his score in CF rounds to be as large as possible.
What is score? In codefires, every problem has 2 attributes, let's call them ki and Bi (KI, Bi> 0 ). if memset137 solves the problem at Ti-th second, he gained bi-ki * ti score. it's guaranteed bi-ki * ti is always positive during the round time.
Now that memsetbench can solve every problem, in this problem, Bi is of no concern. please write a program to calculate the minimal score he will lose. (that is, the sum of KI * ti ).
Input the first line contains an integer N (1 ≤ n ≤ 10 ^ 5), the number of problem in the round.
The second line contains N integers EI (1 ≤ EI ≤ 10 ^ 4), the time (second) to solve the I-th problem.
The last line contains N integers KI (1 ≤ Ki ≤ 10 ^ 4), as was described.
Output one integer L, the minimal score he will lose.
Sample input310 10 201 2 3
Sample output150
HintMemsetasktakes the first 10 seconds to Solve Problem B, then solves problem C at the end of the 30th second. memset137 gets AK at the end of the 40th second. L = 10*2 + (10 + 20) * 3 + (10 + 20 + 10) * 1 = 150.
Author Zhenhai Middle School
Source 2014 multi-university training Contest 2 code:
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 using namespace std; 5 struct node{ 6 int e,t; 7 bool operator < (const node a) const{ 8 return e*a.t>a.e*t; 9 }10 }map[100005];11 int main(){12 int n,i;13 __int64 tat,ans;14 while(scanf("%d",&n)!=EOF){15 for(i=0;i<n;i++)16 scanf("%d",&map[i].t);17 for(i=0;i<n;i++)18 scanf("%d",&map[i].e);19 sort(map,map+n);20 for(ans=tat=i=0;i<n;i++){21 tat+=map[i].t;22 ans+=tat*map[i].e;23 }24 printf("%I64d\n",ans);25 }26 return 0;27 }
View code
2014 --- multi-school training 2 (ZCC loves codefires)