﻿PAT(B) 1020. 月饼 (25)-Ocrosoft

# PAT(B) 1020. 月饼 (25)

```3 20
18 15 10
75 72 45
```

```94.50
```
```#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cctype>
#include <climits>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
#define strend string::npos
#define ms(a) memset(a,0,sizeof(a))
#define rep(a,v,b) for(int a=v;a<b;a++)
#define repe(a,v,b) for(int a=v;a<=b;a++)
#define pre(a,v,b) for(int a=v;a>b;a--)
#define pree(a,v,b) for(int a=v;a>=b;a--)
#define lowbit(x) x&-x
typedef long long LL;
const LL LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const int MAXN = 27 + 10;
const int MOD = 1000000007;
int gcd(int a, int b)
{
if (!b)return a;
return gcd(b, a%b);
}
/*(◕‿‿◕)(◕‿‿◕) (◕‿‿◕) (◕‿‿◕) (◕‿‿◕) (◕‿‿◕)*/
/*(◕‿‿◕) 签订契约,成为马猴烧酒吧 (◕‿‿◕)*/
/*(◕‿‿◕)(◕‿‿◕) (◕‿‿◕) (◕‿‿◕) (◕‿‿◕) (◕‿‿◕)*/
using namespace std;
struct mc
{
mc() {}
mc(double kc, double sj) { this->kc = kc; this->sj = sj; }
double kc;//库存
double sj;//售价
double dj;//单价
bool operator <(const mc other)const
{
return dj > other.dj;
}
};
int main()
{
int n, m;
vector<mc> v;
cin >> n >> m;
rep(i, 0, n)
{
double t; cin >> t;
v.push_back(mc(t, 0));
}
rep(i, 0, n)
{
double t; cin >> t;
v[i].sj = t;
v[i].dj = v[i].sj / v[i].kc;
}
sort(v.begin(), v.end());
double sum = 0;
rep(i, 0, n)
{
if (v[i].kc < m) { sum += v[i].sj; m -= v[i].kc; }
else { sum += 1.0*v[i].sj / v[i].kc*m; break; }
}
printf("%.2lf\n", sum);
return 0;
}```