Saleh127

UVA 11308 / Implementation - String

Mar 27th, 2022
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. /***
  2.  created: 2022-03-27-16.56.58
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. #define ll long long
  8. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  9. #define get_lost_idiot return 0
  10. #define nl '\n'
  11.  
  12.  
  13. bool cmp(pair<ll,string>a,pair<ll,string>b)
  14. {
  15.     if(a.first==b.first)
  16.     {
  17.         return a<b;
  18.     }
  19.     return a<b;
  20. }
  21.  
  22. int main()
  23. {
  24.     ios_base::sync_with_stdio(0);
  25.     cin.tie(0);
  26.     cout.tie(0);
  27.  
  28.  
  29.     test
  30.     {
  31.  
  32.         cin.ignore();
  33.         string a,c,e;
  34.  
  35.         getline(cin,a);
  36.  
  37.         ll n,m,i,j,k,b,l;
  38.         map<string,ll>cst;
  39.         vector<string>item;
  40.  
  41.         cin>>m>>n>>b;
  42.  
  43.         while(m--)
  44.         {
  45.             cin>>c>>k;
  46.             cst[c]=k;
  47.         }
  48.  
  49.         vector<pair<ll,string> >ans;
  50.  
  51.         for(i=0;i<n;i++)
  52.         {
  53.             cin.ignore();
  54.  
  55.             getline(cin,c);
  56.             //item.push_back(c);
  57.  
  58.             cin>>k;
  59.             l=0;
  60.             while(k--)
  61.             {
  62.                 cin>>e>>j;
  63.  
  64.                 l+=(cst[e]*j);
  65.             }
  66.  
  67.             if(l<=b) ans.push_back({l,c});
  68.         }
  69.  
  70.         transform(a.begin(),a.end(),a.begin(), ::toupper);
  71.  
  72.         cout<<a<<nl;
  73.  
  74.         if(ans.size())
  75.         {
  76.             sort(ans.begin(),ans.end());
  77.  
  78.             for(i=0;i<ans.size();i++)
  79.             {
  80.                 cout<<ans[i].second<<nl;
  81.             }
  82.         }
  83.         else
  84.         {
  85.             cout<<"Too expensive!"<<nl;
  86.         }
  87.  
  88.         cout<<nl;
  89.     }
  90.  
  91.     get_lost_idiot;
  92. }
  93.  
Advertisement
Add Comment
Please, Sign In to add comment