Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define mp make_pair
- #define sz size
- #define ll long long
- #define ld long double
- #define fs first
- #define sc second
- #define forn(i, f, t) for(int i = f; i < t; i++)
- #define all(x) (x).begin(), (x).end()
- #define ins insert
- const int INF = 2147483647;
- const int MOD = 1000000007;
- const ll INF64 = 9223372036854775807;
- const ld EPS = 1e-7;
- using namespace std;
- int main(){
- int n, m, k, t, ans = 0;
- string ph, s;
- vector<pair<int, string> > phs;
- cin >> m >> n;
- cin >> s;
- forn(i, 0, n){
- cin >> k >> t;
- cin >> ph;
- phs.pb(mp(t, ph));
- }
- sort(all(phs));
- int cnt = 0;
- forn(i, 0, n)
- forn(j, 0, phs[i].sc.sz())
- forn(k, 0, m)
- if (s[k] == phs[i].sc[j]){
- s[k] = '0';
- ans += phs[i].fs;
- cnt++;
- }
- cout << (cnt == m ? ans : -1) << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement