vovanhoangtuan

1042B - Vitamins

Nov 26th, 2020
451
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. map<string, int> a;
  6.  
  7. const int MAX = 10000000;
  8.  
  9. int main()
  10. {
  11.     int n, c;
  12.     string s;
  13.     a["A"] = a["B"] = a["C"] = a["AB"] = a["AC"] = a["BC"] = a["ABC"] = MAX;
  14.  
  15.     cin >> n;
  16.     for (int i = 0; i < n; i++)
  17.     {
  18.         cin >> c >> s;
  19.         sort(s.begin(), s.end());
  20.         a[s] = min(a[s], c);
  21.     }
  22.  
  23.     int res = a["A"] + a["B"] + a["C"];
  24.     res = min(res, a["AB"] + a["C"]);
  25.     res = min(res, a["AC"] + a["B"]);
  26.     res = min(res, a["BC"] + a["A"]);
  27.     res = min(res, a["AB"] + a["AC"]);
  28.     res = min(res, a["AB"] + a["BC"]);
  29.     res = min(res, a["AC"] + a["BC"]);
  30.     res = min(res, a["ABC"]);
  31.  
  32.     if (res == MAX) cout << -1;
  33.     else cout << res;
  34.  
  35.  
  36.     return 0;
  37. }
  38.  
RAW Paste Data