Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Equal Division problem solution

YASH PAL, 31 July 202415 February 2026
In this HackerEarth Equal Division problem solution, There are N teams in a software company. The ith team has Bi employees in it and a total budget of  units of money. Each team has to divide their budget within their employees equally. But for some teams, it’s not possible to divide the budget equally.
Therefore, the company have to perform revisions in the teams’ budget sizes.
 
In one revision, to revise the budget of ith team, the budget of the first i teams has to be increased by 1.
 
Your task is to find the minimum number of revisions needed so that for each team, equal distribution of their budget among the employees is possible.
 
 
HackerEarth Equal Division problem solution

 

 

HackerEarth Equal Division problem solution.

#include<iostream>
#include<cstdio>
#include<cstring>

typedef long long ll;
const int N=101000;
int A[N],B[N];
int n;
ll ans;

int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d%d",A+i,B+i),A[i]%=B[i];
ans=0;
for(int i=n;i;i--)
{
A[i]=(ans+A[i])%B[i];
if(A[i]!=0)ans+=B[i]-A[i];
}
printf("%lldn",ans);
return 0;
}
 

Second solution

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e5 + 5;
const int INF = 1e9;
long long a[MAX], b[MAX];

int main(int argc, char* argv[]) {
if(argc == 2 or argc == 3) freopen(argv[1], "r", stdin);
if(argc == 3) freopen(argv[2], "w", stdout);
int n;
long long ans;
assert(cin >> n);
assert(1 <= n and n <= 100000);
for (int i = 0; i < n; i++) {
assert(cin >> a[i] >> b[i]);
assert(0 <= a[i] and a[i] <= INF);
assert(1 <= b[i] and b[i] <= INF);
}
assert(!(cin >> n));
ans = 0;
for (int i = n-1; i >= 0; i--) {
a[i] += ans;
ans += ((b[i] - (a[i] % b[i]))) % b[i];
}
cout << ans << endl;
return 0;
}
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes