Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerEarth Utkarsh and Distributing Books problem solution

YASH PAL, 31 July 2024
In this HackerEarth Utkarsh and Distributing Books problem solution Utkarsh’s mother recently received N piles of books as a gift from someone. The ith pile contains Bi books.
She neither wants to keep the voluminous books with herself nor she wants to throw them away. So, she decided to distribute them to students of the nearby school. She decided to call K students to her home and ask one of her sons (Utkarsh or Saharsh) to distribute books.
Also, she will get happy only if the following condition is satisfied: For every pile i there must be at least one student who receives more than one book from pile i.
She knows that Utkarsh is very lazy. So he will randomly pick a student and give him a book from any pile. Since he distributes randomly, he might make her sad.
On the other hand, Saharsh is smart and obedient so he will always find a way of distribution (if possible) that will make her happy.
You need to output 2 integers: The maximum value of K
When Utkarsh is asked to distribute the books. His mother must remain happy irrespective of the way of his distribution.
When Saharsh is asked to distribute the books.
HackerEarth Utkarsh and Distributing Books problem solution

HackerEarth Utkarsh and Distributing Books problem solution.

#include <iostream>
#include <cassert>
using namespace std;

int n;
int a[1010];

void solve() {
cin>>n;
for (int i = 1; i <= n; i++) {
cin>>a[i];
assert(2 <= a[i] && a[i] <= 1000);

}

int minA = 1E9, sum;
for (int i = 1; i <= n; i++) {
minA = min(minA, a[i] - 1);
sum += a[i];

}

cout<<minA<<" "<<sum - n <<endl;

}

int main()
{
int test;
cin>>test;
while (test--) {
solve();
}
return 0;
}
coding problems solutions

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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