Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int used[3];
- int main()
- {
- int n;
- cin >> n;
- vector<pair<int, string> > a(n);
- for (int i = 0; i < n; ++i)
- {
- cin >> a[i].first >> a[i].second;
- }
- sort(a.begin(), a.end());
- vector<pair<int, string> > ans;
- for (int i = 0; i < n; ++i)
- {
- string cur = a[i].second;
- for (int j = 0; j < cur.size();++j)
- if (used[cur[j] - 'A'] == 0)
- {
- ans.push_back(make_pair(a[i].first,cur));
- for (int k = 0; k < cur.size();++k)
- used[cur[k] - 'A']++;
- }
- }
- for (int i = 0; i < 3; ++i)
- if (!used[i])
- {
- cout << -1;
- return 0;
- }
- int answer = 0;
- for (int i = ans.size()-1;i >= 0;--i)
- {
- string cur = ans[i].second;
- bool fl = false;
- for (int j = 0; j < cur.size();++j)
- if (used[cur[j] - 'A'] <= 1)fl = true;
- if (!fl)
- {
- ans[i].first = 0;
- for (int j = 0; j < 3; j++)
- used[j]--;
- }
- answer += ans[i].first;
- }
- cout << answer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement