Anton and Making Potions

题意:

  有一个瓶子每生成一滴药水需要x分钟,有两种加速生产药水的方式。 第一种有m个方案,第i个方案消耗bi个法力值,将每滴要药水的生成时间有x替换到ai 。 第二种有k个方案,第i个方案消耗di个法力值,直接不花费时间生成ci滴药水。 两种方式都只能选择一个方案或者不选择,且要求总消耗的法力值不超过s,问生产n滴药水最少需要多长时间?

lower的意义是对于给定的已经排好序的a,key最能插入到那个位置

0 1 | 2 2 3 所以2最插入到2号位置

upper的意义是对于给定的已经排好序的a,key最能插入到那个位置

0 1 2 2 | 3 所以2最插入到4号位置

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<string>
 6 #include<cmath>
 7 #include<set>
 8 #include<vector>
 9 #include<stack>
10 #include<queue>
11 #include<map>
12 using namespace std;
13 #define ll long long
14 #define se second
15 #define fi first
16 const int INF= 0x3f3f3f3f;
17 const int N=2e5+5;
18 
19 ll n,m,k,w,s,b[N],c[N];
20 
21 struct note
22 {
23     ll x;
24     ll y;
25 }a[N];
26 
27 int main()
28 {
29     scanf("%d%d%d%d%d",&n,&m,&k,&w,&s);
30     for(int i=1;i<=m;i++) scanf("%d",&a[i].x);
31     for(int i=1;i<=m;i++) scanf("%d",&a[i].y);
32     for(int i=1;i<=k;i++) scanf("%d",&b[i]);
33     for(int i=1;i<=k;i++) scanf("%d",&c[i]);
34 
35     ll time=n*w;
36     for(int i=1;i<=k;i++)
37     {
38         if(c[i] <= s){
39             time=min(time, (n-b[i])*w );
40         }
41     }
42     for(int i=1;i<=m;i++)
43     {
44         if(a[i].y <= s){
45             time=min(time, n*a[i].x );
46         }
47     }
48     for(int i=1;i<=m;i++)
49     {
50         if(a[i].y > s) continue;
51 
52         ll aa=upper_bound(c+1,c+1+k, s-a[i].y )-(c+1);
53         if(c[aa] <= s-a[i].y)
54             time=min(time, (n-b[aa])*a[i].x ) ;
55     }
56     cout<<time;
57 }

猜你喜欢

转载自www.cnblogs.com/thunder-110/p/9294071.html
今日推荐