H andy and shopping
Topic links: https://ac.nowcoder.com/acm/contest/940/H
Title Description
andy go to the market to buy n pieces of cargo, the price of each package is A
i
. Businesses in order to attract customers, to buy the N pieces of cargo each customer a discount list, there is little in the fractional N b 1 on the list
j
represents the discount. For each discount b
J
, by the user to decide which to use it to make the price of goods into b
J
* A
i
, and can only be used once.
andy want you to help him count his minimal cost.
Enter a description:
First enter a positive integer t, the number of samples representative of the group. (1≤t≤10)
for each sample:
the first line, enter a positive integer n (1≤n≤1000).
The second line contains n integers, the first integer i a [i] representative of the i-th List item. (1≤a [i] ≤1e9)
The third row contains a number of small n b [i], the title meaning as described. (0≤b [i] ≤1)
Output Description:
For each sample, the output of a real number s, three decimal places, represents the minimum cost.
Example 1
Entry
1 5 1 2 3 4 5 0.1 0.2 0.3 0.4 0.5
Export
3.500
Ideas:
Big big discount original price multiplied with multiplied after its sort to accumulate
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1005; struct node{ int a; double zhe; }Node[1005]; int main() { int t; cin>>t; while(t--) { int n; cin>>n; int x[maxn]; double y[maxn]; for(int i=0;i<n;i++) cin>>x[i]; sort(x,x+n); for(int i=0;i<n;i++) Node[i].a=x[i]; for(int i=0;i<n;i++) cin>>y[i]; sort(y,y+n,greater<double>()); for(int i=0;i<n;i++) Node[i].zhe=y[i]; double sum=0.0; for(int i=0;i<n;i++) sum+=Node[i].a*Node[i].zhe; printf("%.3f\n",sum); } return 0; }