### PROBLEM LINK:

https://www.codechef.com/RSC2017/problems/OVRFWBAS

**Author:** spraveenkumar

### DIFFICULTY:

EASY

### PROBLEM:

There are n baskets each capable of carrying k goods without being unstable. But initially the 'i’th basket have A_{i} goods. The initial state may be unstable. Find out what is the number of more goods that can be added possibly by rearranging the goods across different baskets. If it can’t be made stable, output OFERFLOW.

### QUICK EXPLANATION:

There are n baskets with k capacity. So the total number of goods that can be carried is k x n. As long as the total number of goods across all the baskets is less than kn, we can add goods to it. When they are equal, we can add 0 goods, otherwise it’s OVERFLOW.

### EXPLANATION:

There are n baskets with k capacity each. The baskets maybe unstable initially which can be altered. The total number of goods that can be carried is kn. If the total goods, doesn’t exceed kn, we can add more goods(possibly 0). Otherwise, it is OVERFLOW. But a more efficient way, is to calculate the relative number of goods in each basket. That is, we find the sum of A_{i}-k. When this value is negative, it means, that many goods can be added more. When this is positive, it is overflowing already. In case of 0, it is stable but no more can be added.

### AUTHOR’s SOLUTION:

```
import java.util.Scanner;
class Basket{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- != 0){
int n = sc.nextInt();
int k = sc.nextInt();
int i,a, diff=0;
for(i=0;i<n;i++){
a = sc.nextInt();
diff+=a-k;
}
if(diff>0)
System.out.println("OVERFLOW");
else
System.out.println(-diff);
}
sc.close();
}
}
```