PikMike

Untitled

Jun 10th, 2016
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define pb push_back
  4. #define mp make_pair
  5. #define sz size
  6. #define ll long long
  7. #define ld long double
  8. #define fs first
  9. #define sc second
  10. #define forn(i, f, t) for(int i = f; i < t; i++)
  11. #define all(x) (x).begin(), (x).end()
  12. #define ins insert
  13.  
  14. const int INF = 2147483647;
  15. const int MOD = 1000000007;
  16. const ll INF64 = 9223372036854775807;
  17. const ld EPS = 1e-7;
  18.  
  19. using namespace std;
  20.  
  21.  
  22. int main(){
  23.     int n, m, k, t, ans = 0;
  24.     string ph, s;
  25.     vector<pair<int, string> > phs;
  26.     cin >> m >> n;
  27.     cin >> s;
  28.     forn(i, 0, n){
  29.         cin >> k >> t;
  30.         cin >> ph;
  31.         phs.pb(mp(t, ph));
  32.     }
  33.     sort(all(phs));
  34.     int cnt = 0;
  35.     forn(i, 0, n)
  36.         forn(j, 0, phs[i].sc.sz())
  37.             forn(k, 0, m)
  38.                 if (s[k] == phs[i].sc[j]){
  39.                     s[k] = '0';
  40.                     ans += phs[i].fs;
  41.                     cnt++;
  42.                 }
  43.     cout << (cnt == m ? ans : -1) << "\n";
  44.     return 0;
  45. }
Add Comment
Please, Sign In to add comment