Created
October 17, 2018 22:30
-
-
Save cbdavide/ffb809b42ac08ca2c2194b810f669b0f to your computer and use it in GitHub Desktop.
UVa 12124 - Assemble
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define F first | |
#define S second | |
#define PB push_back | |
#define endl '\n' | |
typedef long long ll; | |
typedef vector<ll> vll; | |
typedef pair<int, int> ii; | |
typedef vector<ii> vii; | |
typedef vector<int> vi; | |
const int INF = ~(1 << 31); | |
map<string, vi> Q, P; | |
bool check(int q, int budget) { | |
ll sum = 0LL; | |
map<string, vi>::iterator it; | |
for(it = Q.begin(); it != Q.end(); it++) { | |
string type = (*it).F; | |
vi quality = (*it).S; | |
vi price = P[type]; | |
int mn = INF; | |
for(int i=0; i<quality.size(); i++) { | |
if(quality[i] >= q && price[i] < mn) | |
mn = price[i]; | |
} | |
if(mn == INF) return false; | |
sum += mn; | |
} | |
return sum <= budget; | |
} | |
int main() { | |
ios_base::sync_with_stdio(false); | |
cin.tie(NULL); | |
int t, n, b, p, q; | |
string type, name; | |
cin >> t; | |
while(t--) { | |
cin >> n >> b; | |
vi A(n); | |
Q.clear(); P.clear(); | |
for(int i=0; i<n; i++) { | |
cin >> type >> name >> p >> q; | |
Q[type].PB(q); | |
P[type].PB(p); | |
A[i] = q; | |
} | |
sort(A.rbegin(), A.rend()); | |
vi::iterator it = unique(A.begin(), A.end()); | |
A.resize( distance( A.begin(), it ) ); | |
for(int i : A) { | |
if(check( i, b )) { | |
cout << i << endl; | |
break; | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment