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 Bus Journey problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth Bus Journey problem solution, It is a lovely day in Astana, Kazakhstan, and our friend Mahamba is headed to the international exhibition EXPO2017. The route to the main pavilion consists of N bus stops, and Mahamba will leave the bus at the Nth stop. Additionally, the bus has M seats and can support an infinite number of standing people.
 
Mahamba is sitting on the bus already, and it is approaching the first bus stop. By pure luck, he knows that ai adults will enter and bi sitting adults will leave on the ith bus stop for every 1 <= i < N (if there are no sitting adults, no one will leave). He also knows that people leave and only then do new people come in. As Mahamba is a schoolboy, he must give his place to an adult person.
 
If a sitting person leaves the bus, a standing adult will take his place. After there are no standing adults left on the bus and there is a vacant place, he can finally sit down. Mahamba now wants to know how many stops he will ride standing up, as it is a very tiring experience.
 
 
HackerEarth Bus Journey problem solution

 

 

HackerEarth Bus Journey problem solution.

#include <bits/stdc++.h>
#define F first
#define S second
#define EPS 1e-9
#define endl 'n'
#define PI acos(-1)
#define LL long long
#define PB push_back
#define MP make_pair
#define PPB pop_back
#define PF push_front
#define PPF pop_front
#define MOD 1000000007
#define PLL pair<LL, LL>
#define PII pair<int, int>
#define sz(a) (int)a.size()
#define ULL unsigned long long
#define all(v) v.begin(), v.end()
using namespace std;

inline void boost() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
}

const int MXN = 1e5 + 5;

LL m, sit, stnd, a[MXN], b[MXN];
int n, ans;

int main () {
boost();
cin >> n >> m;
for (int i = 1;i < n; i++) {
cin >> a[i] >> b[i];
sit -= b[i];
stnd += a[i];
while (sit < m && stnd > 0)
stnd--, sit++;
if (sit == m)
ans++;
}
cout << ans;
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