-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1020.c
98 lines (90 loc) · 2.32 KB
/
1020.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// #include<stdio.h> //扣2分
// void bsort(double a[], int b[], int c[], int n)
// {
// int i,j;
// for(i=0;i<n-1;i++)
// {
// for(j=n-1;j>i;j--)
// {
// if(a[j]>a[j-1])
// {
// int t;
// t = b[j];
// b[j] = b[j - 1];
// b[j -1] = t;
// int temp;
// temp=c[j];
// c[j]=c[j-1];
// c[j-1]=temp;
// double tem;
// tem = a[j];
// a[j] = a[j - 1];
// a[j - 1] = tem;
// }
// }
// }
// }
// int main()
// {
// int kind, need, sum = 0;
// double money = 0.0;
// scanf("%d %d", &kind, &need);
// int num[1000] = {0}, allprice[1000] = {0};
// double perprice[1000] = {0};
// for(int i = 0; i < kind; i++){
// scanf("%d", &num[i]);
// }
// for(int i = 0; i < kind; i++){
// scanf("%d", &allprice[i]);
// perprice[i] = allprice[i] / (num[i] * 1.0);
// }
// bsort(perprice, num, allprice,kind);
// int i = 0;
// while(need){
// if(num[i] < need){
// if(num[i] == 0){
// break;
// }
// money = money + allprice[i];
// need -= num[i];
// i++;
// }else{
// money += (perprice[i] * need);
// need = 0;
// i++;
// }
// }
// printf("%.2lf", money);
// return 0;
// }
#include <stdio.h>
int main()
{
int kind, max;
double need, num[1000], sum = 0, allprice[1000];
scanf("%d %lf", &kind, &need);
for(int i = 0; i < kind; i++){
scanf("%lf", &num[i]);
}
for(int i = 0; i < kind; i++){
scanf("%lf", &allprice[i]);
}
while(need > 0)
{
max = 0;
for(int i = 0; i < kind; i++){
if(allprice[i] / num[i] > allprice[max] / num[max]) //搞不懂为什么求出均价来比较倒数第四个测试点过不了
max = i;
}
if(num[max] < need){
sum += allprice[max];
need -= num[max];
allprice[max] = 0;
}else{
sum += allprice[max] * need / num[max];
need = 0;
}
}
printf("%.2f", sum);
return 0;
}