title: Can You please explain to me where's the problem? [SPOj-exercise]
body: <p>I mean I honestly can't find the issue and this code seems to be very simple to write and I don't get accepted. Maybe You can help me and find the answer as honestly I have no idea. I'm trying to do this exercise on SPOJ: <a href="https://www.spoj.com/problems/PIGBANK/" rel="nofollow noreferrer">https://www.spoj.com/problems/PIGBANK/</a>. I will be very thankful for any explanation on what is wrong in my approach.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  void piggyBank(int, int);
  int sumAll(int *,int, int);
  
  
  /* SUMMARY
  
      We need to find the smallest value available in the piggy bank
  
  */
  
  int main()
  {
      int t = 0, e = 0, f = 0;
      cin &gt;&gt; t;
      for (int i = 0; i &lt; t; i++)
      {
          cin &gt;&gt; e &gt;&gt; f;
          piggyBank(e, f);
      }
      return 0;
  }
  
  void piggyBank(int weightEmpty, int weightFull)
  {
      int coinsAmount = 0, *coinValue, *coinWeight, totalWorth = 0, remainingWeight = weightFull - weightEmpty, smallestValPos = 0;
      cin &gt;&gt; coinsAmount;
      coinValue = new int[coinsAmount];
      coinWeight = new int[coinsAmount];
      // getting all the coins and weights in the piggy bank
      for (int i = 0; i &lt; coinsAmount; i++)
      {
          cin &gt;&gt; coinValue[i] &gt;&gt; coinWeight[i];
          if ((remainingWeight / coinWeight[smallestValPos] &gt; remainingWeight / coinWeight[i]) &amp;&amp; (remainingWeight % coinWeight[i] == 0)) smallestValPos = i;
      }
      // we need to check how many coinValue[smallestValPos] are there inside piggy bank
      if(remainingWeight%coinWeight[smallestValPos] == 0)totalWorth = remainingWeight / coinWeight[smallestValPos] * coinValue[smallestValPos];
      // output according to the excercise's constraints
      if (totalWorth == 0) cout &lt;&lt; "This is impossible.\n";// &lt;&lt; endl;
      else cout &lt;&lt; "The minimum amount of money in the piggy-bank is " &lt;&lt; totalWorth &lt;&lt; ".\n"; //&lt;&lt; endl;
  }
  
  int sumAll(int *tab,int start, int end)
  {
      int sum = 0;
      for (int i = start; i &lt; end; i++)
      {
          sum += tab[i];
      }
      return sum;
  }
  </code></pre>
  
  <p>Sample Input from SPOJ:</p>
  
  <p>3
  10 110
  2
  1 1
  30 50
  10 110
  2
  1 1
  50 30
  1 6
  2
  10 3
  20 4</p>
  
  <p>Sample output from SPOJ:</p>
  
  <p>The minimum amount of money in the piggy-bank is 60.
  The minimum amount of money in the piggy-bank is 100.
  This is impossible.</p>