Help me in solving TIES problem

My issue

how to practice these type of questions??

My code

#include <bits/stdc++.h>
using namespace std;
void solve()
    int n;
    int sum=0;
    bool flag=false;
    for(int i=0;i<n;i++){
    int sum2=0;
    for(int i=0;i<n;i++)
        int vl=v[i]/2;
    if((!flag) && (sum2%n)==0){
    cout << "Yes" << endl;
    cout << "No" << endl;
int main() {
	int t;
	return 0;

Problem Link: TIES Problem - CodeChef

Let me help you to break down this number:-

  1. If the total chocolates is not divisible by number of people we cant divide them equally so we return NO.
  2. If total%size == 0, we need to know whether he can equalize without compromising the given condition i.e., he can take 2^k chocolate and give to another.
  3. To know weather he can divide with out breaking the rule first lets know how many chocolates each has to have so we do (total/size)
  4. Now search for the person who has more than (total/size) chocolates why because only he can give chocloates to whom have less.
  5. Now from that person chocolates subtract the (total/size) chocolates from it , so that reamining chocolates he can share with other.
  6. Now the condition can he share according to the condition or nor to check that we simply divide the remaining chocolate with 2 if it is divisible ok continue if not we break the loop and print NO if we cant find the person who cant share which means we can equalize so we return yes.
    Hope you understand.