Advertisement
bappi2097

CF-Beta-3-Problem-B

Jul 26th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. struct Lorry
  4. {
  5.     int type;
  6.     int cap;
  7.     double pri;
  8.     bool av=true;
  9.     int rnk;
  10. };
  11. bool func(const Lorry &x,const Lorry &y)
  12. {
  13.     return x.pri>y.pri;
  14. }
  15. int main()
  16. {
  17.     ios_base::sync_with_stdio(false);
  18.     cin.tie(NULL);
  19.     #ifndef ONLINE_JUDGE
  20.     freopen("input.txt","r",stdin);
  21.     freopen("output.txt","w",stdout);
  22.     #endif // ONLINE_JUDGE
  23.     int n,v,sum=0,lorry=0;
  24.     cin>>n>>v;
  25.     vector<Lorry> vec(n);
  26.     vector<int> pos;
  27.     for(int i=0; i<n; i++)
  28.     {
  29.         cin>>vec[i].type>>vec[i].cap;
  30.         vec[i].pri=(double)vec[i].cap/vec[i].type;
  31.         vec[i].rnk=i+1;
  32.     }
  33.     sort(vec.begin(),vec.end(),func);
  34.     for(int j=0; j<n; j++)
  35.     {
  36.         for(auto i=vec.begin(); i!=vec.end(); i++)
  37.         {
  38.             if(i->av && sum+i->type<=v)
  39.             {
  40.                 sum+=i->type;
  41.                 i->av=false;
  42.                 pos.push_back(i->rnk);
  43.                 lorry+=i->cap;
  44.                 break;
  45.             }
  46.         }
  47.     }
  48.     cout<<lorry<<endl;
  49.     for(auto i=pos.begin();i!=pos.end();i++)cout<<*i<<' ';
  50.     cout<<endl;
  51.     //for(int i=0; i<n; i++)cout<<vec[i].type<<' '<<vec[i].cap<<' '<<vec[i].pri<<' '<<vec[i].av<< ' '<<vec[i].rnk<<endl;
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement