Code C++ :
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll ;
int main() {
ll n;
cin>>n ;
ll k;
cin>>k;
ll v[n+1]={0};
ll b[n+1]={0};
ll i = 1 ;
while(i<=n){
cin>>v[i];
i++;
}
i = 1 ;
while(i<=n){
cin>>b[i];
i++;
}
vector <pair<ll,ll>> pr ;
i = 1 ;
while(i<=n){
pr.push_back({b[i],v[i]});
i++;
}
sort(pr.begin(),pr.end());
reverse(pr.begin(),pr.end());
ll sum = 0 ;
i = 0 ;
while(i<=n-1){
cout<<pr[i].first<<" "<<pr[i].second;
cout<<"\n";
//sum+=(stor[i]);
if(k>=pr[i].second){
sum +=(pr[i].first*pr[i].second);
k = k - pr[i].second ;
// pr[i].second = 0 ;
} else {
sum +=(pr[i].first*k);
k = 0 ;
i = 1e18 ;
}
i++;
}
// cout<<sum ;
cout<<sum ;
return 0 ;
}