title: How can I optimise this to run in an efficient manner?
body: <p>The link for the question is as follows: <a href="http://codeforces.com/problemset/problem/478/C" rel="nofollow">http://codeforces.com/problemset/problem/478/C</a></p>
  
  <p>You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can be decorated if we know number of balloons of each color?</p>
  
  <p>Your task is to write a program that for given values r, g and b will find the maximum number t of tables, that can be decorated in the required manner.</p>
  
  <p>Input:
  The single line contains three integers r, g and b (0 ≤ r, g, b ≤ 2·10^9) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.</p>
  
  <p>Output:
  Print a single integer t — the maximum number of tables that can be decorated in the required manner.</p>
  
  <p>So, what I did was, in a greedy manner, searched for the maximum and minimum value each time and subtracted 2 and 1 respectively if possible. Here is my code:</p>
  
  <pre><code>int main (void)
  {
      int ans=0,r,g,b;
      cin&gt;&gt;r&gt;&gt;g&gt;&gt;b;
      while (1)
      {
          int a1 = maxfind(r,g,b);
          int a2 = minfind(r,g,b);
          //ans++;
          if (a1 &gt;= 2 &amp;&amp; a2 &gt;= 1)
          {
              ans++;
              if (indma == 1)
                  r = r-2;
              else if (indma == 2)
                  g = g-2;
              else 
                  b = b-2;
              if (indmi == 1)
                  r = r-1;
              else if (indmi == 2)
                  g = g-1;
              else
                  b = b-1;
          }
          else if (r == 1 &amp;&amp; g == 1 &amp;&amp; b == 1)
          {
              ans++;
              break;
          }
          else
              break;
  
      }
      cout&lt;&lt;ans&lt;&lt;"\n";
  
  int maxfind(int r, int g, int b)
  {
      indma = 0;
      int temp = INT_MIN;
      if (r &gt;= temp)
      {
          temp = r;
          indma = 1;
      }
      if (g &gt;= temp)
      {
          temp = g;
          indma = 2;
      }
      if (b &gt;= temp)
      {
          temp = b;
          indma = 3;
      }
      return temp;
  }
  </code></pre>
  
  <p>Similar is the function for <code>findmin</code> and I make sure that it's not the same number chosen in case the maximum and minimum values are same. However, since the limit is 2*10^9, obviously, this surpasses the Time limit. How can I optimise it? Thanks!</p>
  
  <p>Edit: You can easily find sample test cases in the link for the question. However, I am still adding one of them. </p>
  
  <pre><code>Input
  5 4 3
  output
  4
  </code></pre>
  
  <p>Explanation: In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively.</p>