SHARE
TWEET

Untitled

a guest Sep 20th, 2019 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  main.cpp
  3. //  Витамины
  4. //
  5. //  Created by Владислав on 05/09/2019.
  6. //  Copyright © 2019 Владислав. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <string>
  11. #include <cmath>
  12. #include <algorithm>
  13. #define int long long
  14.  
  15. using namespace std;
  16.  
  17. int n, mina, minb, minc, minab, minac, minbc, minabc;
  18.  
  19. signed main() {
  20.     cin >> n;
  21.     mina = 1000000000, minb = 1000000000, minc = 1000000000, minab = 1000000000, minac = 1000000000, minbc = 1000000000, minabc = 1000000000;
  22.     for(int i = 0; i < n; i++) {
  23.         int c;
  24.         string s;
  25.         cin >> c >> s;
  26.         if(s == "A") {
  27.             mina = min(mina, c);
  28.         }
  29.         if(s == "B") {
  30.             minb = min(minb, c);
  31.         }
  32.         if(s == "C") {
  33.             minc = min(minc, c);
  34.         }
  35.         if(s == "AB" || s == "BA") {
  36.             minab = min(minab, c);
  37.         }
  38.         if(s == "AC" || s == "CA") {
  39.             minac  = min(minac, c);
  40.         }
  41.         if(s == "BC" || s == "CB") {
  42.             minbc = min(minbc, c);
  43.         }
  44.         if(s == "ABC" || s == "ACB" || s == "CAB" || s == "CBA" || s == "CAB" || s == "BAC" || s == "BCA") {
  45.             minabc = min(minabc, c);
  46.         }
  47.     }
  48.     int ans = 1000000000;
  49. //    cout << mina << " " << minb << " " << minc << '\n';
  50.     ans = min(mina + minb + minc, minabc);
  51.     ans = min(ans, minab + minc);
  52.     ans = min(ans, minac + minb);
  53.     ans = min(ans, minbc + mina);
  54.     ans = min(ans, minab + minbc);
  55.     ans = min(ans, minab + minac);
  56.     ans = min(ans, minac + minbc);
  57.     if(ans >= 1e6) {
  58.         cout << -1 << '\n';
  59.         return 0;
  60.     }
  61.     cout << ans << '\n';
  62.     return 0;
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top