Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- struct Lorry
- {
- int type;
- int cap;
- double pri;
- bool av=true;
- int rnk;
- };
- bool func(const Lorry &x,const Lorry &y)
- {
- return x.pri>y.pri;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- #ifndef ONLINE_JUDGE
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- #endif // ONLINE_JUDGE
- int n,v,sum=0,lorry=0;
- cin>>n>>v;
- vector<Lorry> vec(n);
- vector<int> pos;
- for(int i=0; i<n; i++)
- {
- cin>>vec[i].type>>vec[i].cap;
- vec[i].pri=(double)vec[i].cap/vec[i].type;
- vec[i].rnk=i+1;
- }
- sort(vec.begin(),vec.end(),func);
- for(int j=0; j<n; j++)
- {
- for(auto i=vec.begin(); i!=vec.end(); i++)
- {
- if(i->av && sum+i->type<=v)
- {
- sum+=i->type;
- i->av=false;
- pos.push_back(i->rnk);
- lorry+=i->cap;
- break;
- }
- }
- }
- cout<<lorry<<endl;
- for(auto i=pos.begin();i!=pos.end();i++)cout<<*i<<' ';
- cout<<endl;
- //for(int i=0; i<n; i++)cout<<vec[i].type<<' '<<vec[i].cap<<' '<<vec[i].pri<<' '<<vec[i].av<< ' '<<vec[i].rnk<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement