-
Notifications
You must be signed in to change notification settings - Fork 0
/
1020.cpp
145 lines (145 loc) · 2.88 KB
/
1020.cpp
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<<<<<<< HEAD
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#include<unordered_set>
#define rg register ll
#define inf 2147483647
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define ll long long
#define maxn 300005
#define lb(x) (x&(-x))
const double eps = 1e-6;
using namespace std;
inline ll read()
{
char ch = getchar(); ll s = 0, w = 1;
while (ch < 48 || ch>57) { if (ch == '-')w = -1; ch = getchar(); }
while (ch >= 48 && ch <= 57) { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
return s * w;
}
inline void write(ll x)
{
if (x < 0)putchar('-'), x = -x;
if (x > 9)write(x / 10);
putchar(x % 10 + 48);
}
struct node
{
double a,b,c;
}p[1005];
ll n,d,a[1005],b[1005];
inline bool cmp(const node&q,const node&w)
{
if(q.c==w.c)return q.a>w.a;
return q.c>w.c;
}
int main()
{
cin>>n>>d;
for(rg i=1;i<=n;i++)
{
cin>>p[i].a;
}
for(rg i=1;i<=n;i++)
{
cin>>p[i].b;
}
for(rg i=1;i<=n;i++)
{
p[i].c=p[i].b/(p[i].a*1.0);
//cout<<p[i].c<<endl;
}
sort(p+1,p+1+n,cmp);
double sum=0;
double ans=0;
for(rg i=1;i<=n;i++)
{
if(sum+p[i].a<=d)
{
ans+=p[i].b;
sum+=p[i].a;
}
else
{
ans+=(d-sum)*p[i].b*1.0/(1.0*p[i].a);
break;
}
//cout<<ans<<endl;
}
cout<<setiosflags(ios::fixed)<<setprecision(2)<<ans<<endl;
return 0;
}
=======
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#include<unordered_set>
#define rg register ll
#define inf 2147483647
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define ll long long
#define maxn 300005
#define lb(x) (x&(-x))
const double eps = 1e-6;
using namespace std;
inline ll read()
{
char ch = getchar(); ll s = 0, w = 1;
while (ch < 48 || ch>57) { if (ch == '-')w = -1; ch = getchar(); }
while (ch >= 48 && ch <= 57) { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
return s * w;
}
inline void write(ll x)
{
if (x < 0)putchar('-'), x = -x;
if (x > 9)write(x / 10);
putchar(x % 10 + 48);
}
struct node
{
double a,b,c;
}p[1005];
ll n,d,a[1005],b[1005];
inline bool cmp(const node&q,const node&w)
{
if(q.c==w.c)return q.a>w.a;
return q.c>w.c;
}
int main()
{
cin>>n>>d;
for(rg i=1;i<=n;i++)
{
cin>>p[i].a;
}
for(rg i=1;i<=n;i++)
{
cin>>p[i].b;
}
for(rg i=1;i<=n;i++)
{
p[i].c=p[i].b/(p[i].a*1.0);
//cout<<p[i].c<<endl;
}
sort(p+1,p+1+n,cmp);
double sum=0;
double ans=0;
for(rg i=1;i<=n;i++)
{
if(sum+p[i].a<=d)
{
ans+=p[i].b;
sum+=p[i].a;
}
else
{
ans+=(d-sum)*p[i].b*1.0/(1.0*p[i].a);
break;
}
//cout<<ans<<endl;
}
cout<<setiosflags(ios::fixed)<<setprecision(2)<<ans<<endl;
return 0;
}
>>>>>>> a45269a6f9ce61abed19a3dbc4d5ff91c7b4ed44