-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp1477.cpp
More file actions
45 lines (37 loc) · 737 Bytes
/
p1477.cpp
File metadata and controls
45 lines (37 loc) · 737 Bytes
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
#include<iostream>
#include<algorithm>
using namespace std;
struct sm{
int v;
int w;
};
int cmp(sm a,sm b){
return a.v*b.w>b.v*a.w;
}
int main(){
int n,W;
int temp;
while(cin>>n>>W){
sm a[n];
for(int i=0;i<n;i++){
cin>>temp;
a[i].w=temp;
cin>>temp;
a[i].v=temp;
}
sort(a,a+n,cmp);
int i;
double sum=0;
for(i=0;i<n;i++){
if(a[i].w<W){
W=W-a[i].w;
sum+=a[i].v;
}else{
sum=sum+a[i].v*(W)*1.0/(a[i].w*1.0);
break;
}
}
printf("%.2lf\n",sum);
}
return 0;
}