pipioj 1028: 可乐(贪心)

http://www.pipioj.online/problem.php?id=1028

 1 #define IO std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
 2 #define bug(x) cout<<#x<<" is "<<x<<endl
 3 #include <bits/stdc++.h>
 4 #define iter ::iterator
 5 using namespace  std;
 6 typedef long long ll;
 7 typedef pair<int,ll>P;
 8 #define pb push_back
 9 #define mk make_pair
10 #define se second
11 #define fi first
12 #define rs o*2+1
13 #define ls o*2
14 const ll mod=1e9+7;
15 const int N=2e5+5;
16 int T,n,k;
17  
18 ll a[35],v[35],res[35];
19  
20 ll L;
21  
22 struct node{
23     ll x;
24     int id;
25 }b[35];
26  
27 bool cmp(node p,node q){
28     return p.x<q.x;
29 }
30  
31 int main(){
32     IO;
33     while(cin>>n>>L){
34         for(int i=1;i<=n;i++)cin>>a[i],v[i]=(1<<(i-1)),res[i]=0;
35  
36         ll h=1;
37         for(int i=n;i>=1;i--){
38             b[i].id=i;
39             b[i].x=a[i];
40             b[i].x*=h;
41             h*=2;
42         }
43  
44         sort(b+1,b+1+n,cmp);
45         ll ans=0,res=1e18;
46         for(int i=1;i<=n;i++){
47             if(L>=v[b[i].id]){
48                 ll x=L/v[b[i].id];
49                 ans+=x*a[b[i].id];
50                 L-=x*v[b[i].id];
51             }
52             if(!L)break;
53             res=min(res,ans+a[b[i].id]);
54         }
55         ans=min(ans,res);
56         cout<<ans<<endl;
57     }
58 }

 

posted @ 2021-03-09 02:47  Venux  阅读(75)  评论(0)    收藏  举报