Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ull unsigned long long
- #define uom unordered_map
- #define pb push_back
- #define yes cout<<"YES\n"
- #define no cout<<"NO\n"
- #define dot(x) fixed<<setprecision(x)
- #define wrench786 ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
- #define PI (acos(-1.0))
- #define eps 0.00001
- const int LIMIT = 10000*100;
- const int mod = 1000000007;
- using namespace std;
- bool cmp(pair<int,int>a, pair<int,int>b){
- double x = (double)a.first/a.second;
- double y = (double)b.first/b.second;
- if(x>=y)return true;
- else return false;
- }
- void solve(){
- int capacity,n,i,j;
- scanf("%d %d", &n, &capacity);
- int price[n];
- int weight[n];
- vector<pair<int,int>>price_weight;
- for(i=0;i<n;i++){
- scanf("%d",&price[i]);
- }
- for(i=0;i<n;i++){
- scanf("%d",&weight[i]);
- }
- for(i=0;i<n;i++){
- price_weight.pb(make_pair(price[i],weight[i]));
- }
- //sort(price_weight.begin(),price_weight.end(),cmp);
- for(i=0;i<n;i++){
- for(j=i+1;j<n;j++){
- if(cmp(price_weight[i],price_weight[j])){
- continue;
- }
- else{
- swap(price_weight[i],price_weight[j]);
- }
- }
- }
- double ans_price=0.0;
- double ans_weight=0.0;
- for(i=0;i<n;i++){
- if(ans_weight<(double)capacity){
- if(ans_weight+price_weight[i].second<=capacity){
- ans_weight+=price_weight[i].second;
- ans_price+=price_weight[i].first;
- cout<<"Taken weight = "<<price_weight[i].second<<endl;
- cout<<"Taken Price = "<<price_weight[i].first<<endl;
- }
- else{
- ans_price+= (price_weight[i].first *(capacity-ans_weight))/ (double)price_weight[i].second;
- ans_weight+= capacity-ans_weight;
- break;
- }
- }
- else{
- break;
- }
- }
- cout<<ans_price<<" "<<ans_weight<<endl;
- }
- int main(){
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement