flag=1;
sum = sum+arr[k];
sum=arr[k];
Add a number to sum, then immediately overwrite it with the number. You need to think more about what your codse is supposed to be doing. Before you code it write down the steps that you need it to do, one by one. Note that you always set flag to 1, so you will always print "YES" at the end.