-
Notifications
You must be signed in to change notification settings - Fork 0
/
1070.cpp
62 lines (55 loc) · 1.17 KB
/
1070.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
//
// main.cpp
// test
//
// Created by 李寻欢 on 2019/9/23.
// Copyright © 2019 李寻欢. All rights reserved.
//
#include <stdio.h>
#include <iostream>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <unordered_map>
#include <string.h>
using namespace std;
vector<double> v;
typedef pair<double, int> pp;
vector<pp> price;
bool cmp(pp &a,pp &b){
return a.first > b.first;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
double n,m;
cin >> n >> m;
for (int i=0; i<n; ++i){
double t;
cin >> t;
v.push_back(t);
}
for (int i=0;i<n;++i){
pp temp;
cin >> temp.first;
temp.first /= v[i];
temp.second = i;
price.push_back(temp);
}
sort(price.begin(), price.end(), cmp);
double ans = 0;
for (int i=0; i<n && m>0; ++i) {
if(v[price[i].second] >= m){
ans += m*price[i].first;
m -= v[price[i].second];
}else{
m -= v[price[i].second];
ans += v[price[i].second]*price[i].first;
}
}
printf("%.2f",ans);
}