PSYCHAMERON

Bear

Jun 14th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int sum;
  5. int cnt[105];
  6. int maxInd;
  7. vector<int> cards;
  8.  
  9. void init();
  10. void solve();
  11.  
  12. int main()
  13. {
  14.     init();
  15.  
  16.     int temp;
  17.     for(int i = 1; i <= 5; i++)
  18.     {
  19.         cin >> temp;
  20.         cards.push_back(temp);
  21.         sum += temp;
  22.     } // end of for
  23.  
  24.     solve();
  25.  
  26.     return 0;
  27. }
  28.  
  29. void init()
  30. {
  31.     memset(cnt, 0, 105);
  32.     sum = 0;
  33.     maxInd = 0;
  34. }
  35.  
  36. void solve()
  37. {
  38.     int sz = cards.size();
  39.     int val;
  40.  
  41.     for(int i = 0; i < sz; i++)
  42.     {
  43.         val = cards[i];
  44.         cnt[val]++; // increase the count
  45.  
  46.         if(cnt[maxInd]*maxInd > cnt[val]*val && cnt[maxInd] > 1) continue;
  47.         if(cnt[maxInd] < cnt[val])
  48.         {
  49.             maxInd = val;
  50.         } // end of if
  51.         else if(cnt[maxInd]*maxInd < cnt[val]*val && maxInd < val && cnt[val] > 1)
  52.         {
  53.             maxInd = val;
  54.         } // end of if
  55.     } // end of for
  56.  
  57.     if(cnt[maxInd] > 3) cnt[maxInd] = 3;
  58.     if(cnt[maxInd] != 1)
  59.     {
  60.         sum -= cnt[maxInd]*maxInd;
  61.     }
  62.     cout << sum;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment