"Sharing CANDY" on SPOJ
This is really silly:


while(k &gt; avg) //Adds the moves 
{
    k-- ;
    cnt++ ;
}



When you can do the same thing in one step:

if (k &gt; avg) cnt += k - avg;


I don't see anything else to make this faster. But there are many many coding style issues.

Limit the scope of variables

Instead of declaring all the variables at the top,
it's better to declare them in the smallest scope, for example:

int avg = sum/t;
for(int i = 0 ; i &lt; t ; i++)
{
    int k = n[i];               
    if (k &gt; avg) cnt += k - avg;
}   


Use the right types

Why do you read the numbers into a string?
The program won't work if a pocket contains more than 9 candies,
which it might, since the requirement states "less than 1000".
Use an int[] instead.

Misc


You should not using namespace std
You're mixing C++ style input/output using cin/cout and old-style scanf/printf. Since you're in C++, you should use C++ everywhere consistently
It's recommended to use braces even with single-statement ifs and loops
After the break statement, you can simplify a bit by eliminating the else block


Corrected and improved implementation

With the above suggestions, the implementation becomes:

#include &lt;iostream&gt;
#include &lt;stdio.h&gt;

int main()
{
    while(true)
    {
        int t;
        std::cin &gt;&gt; t;
        if (t == -1) {
            break;
        }

        int sum = 0;
        int n[t];
        for(int i = 0 ; i &lt; t ; i++)
        {
            std::cin &gt;&gt; n[i];
            sum += n[i];
        }

        if (sum % t != 0) {
            std::cout &lt;&lt; "-1" &lt;&lt; std::endl;   
            continue;
        }

        int avg = sum/t;
        int cnt = 0;
        for(int i = 0 ; i &lt; t ; i++)
        {
            int k = n[i];               
            if (k &gt; avg) cnt += k - avg;
        }   
        std::cout &lt;&lt; cnt &lt;&lt; std::endl;
    }
}


Take special note as to how each variable is declared and initialized right before it's really needed.