Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • 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

HackerEarth Bus Journey problem solution

YASH PAL, 31 July 2024
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

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes