02 July 2015

UVA 11308 - Bankrupt Baker (MAP)

/***
Md. Namzul Hasan
Shahjalal University of Science & technology,sylhet.
hasan08sust@gmail.com
Problem id : 11308
verdict: accepted
***/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cctype>
#include<sstream>
#include<stdlib.h>
#include<map>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))

typedef std::pair <long long, string> IntPair;
vector<pair<long long, string> >v;
int main()
{
    long long i, t, j, k, total, sum, i1;
    cin >> t;
    string x, y, x1, x2;
    int n, m, b, c;
    map<string, long long>store;
    map<long long, string>v1;

    for (i1 = 1; i1 <= t; i1++)
    {
        getchar();
        getline(cin, x1);
        cin >> n >> m >> b;
        for (j = 1; j <= n; j++)
        {
            cin >> x >> c;
            store[x] = c;

        }
        for (k = 1; k <= m; k++)
        {
            getchar();
            getline(cin, x2);
            cin >> total;
            sum = 0;
            for (j = 1; j <= total; j++)
            {
                cin >> x >> c;
                sum = sum + (store[x])*c;
            }
            if (sum <= b)
            {
                v.push_back(make_pair(sum,x2));
            }
        }
        transform(x1.begin(), x1.end(), x1.begin(), ::toupper);
        sort(v.begin(), v.end());
        cout << x1 << "\n";
        if (v.size() > 0)
        {
            for (i = 0; i < v.size(); i++)
            {
                cout << v[i].second << "\n";
            }
        }
        else
        {
            cout << "Too expensive!\n";
        }
        cout << "\n";
        store.clear();
        v.clear();
    }
    return 0 ;
}

No comments:

Post a Comment

UVA 10679 - I Love Strings!!