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 [Only for Data Science] – Bank Happiness Index problem solution

YASH PAL, 31 July 2024
In this HackerEarth [Only for Data Science] – Bank Happiness Index problem solution you are given data of customers that visit a bank in a day. The data contains the following details: (Customer ID, Entry time, Maximum wait time, Happiness Factor, time required for work completion). There N are such customers. There are only K members in the staff that can assist these customers. Given the data, you need to assign these K staff members to the customers in such a way that the total happiness at the end of the day is as maximum possible. There are the following constraints of assigning the staff members – 
  1. You can assign a staff member to at most one person at a time.
  2. The closing time of the bank is 5:30 PM i.e. (1050th minute of the day). The time allocation should not be greater than that. Also, you need to allocate time in such a way that its completion time from the start does not exceed 1050.
  3. The wait time of a particular customer includes its work completion time. Also, the customer remains in the bank even if his wait time gets over till 1050th minute of the day.
hackerEarth [Only for Data Science] - Bank Happiness Index problem solution

hackerEarth [Only for Data Science] – Bank Happiness Index problem solution.

#include<bits/stdc++.h>
#define LL long long int
#define M 1000000007
#define endl "n"
#define eps 0.00000001
LL pow(LL a,LL b,LL m){ a%=m;LL x=1,y=a;while(b > 0){if(b%2 == 1){x=(x*y);if(x>m) x%=m;}y = (y*y);if(y>m) y%=m;b /= 2;}return x%m;}
LL gcd(LL a,LL b){if(b==0) return a; else return gcd(b,a%b);}
LL gen(LL start,LL end){LL diff = end-start;LL temp = rand()%start;return temp+diff;}
using namespace std;
LL id[100001], entry[100001], wait[100001], req_time[100001];
double happiness[100001];
LL allocation_time[100001], staff_id[100001];
LL busy[100001];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
assert(cin >> n >> k);
assert(n >= 1 && n <= 100000);
assert(k >= 1 && k <= 100000);
for(int i = 1; i <= n; i++) {
cin >> id[i] >> entry[i] >> wait[i] >> happiness[i] >> req_time[i];
assert(id[i] >= 0 && id[i] <= 1e9);
assert(wait[i] >= req_time[i] && wait[i] <= 180);
}
double score = 0.0;
vector<pair<pair<int,int> , int> > status;
for(int i = 1; i <= n; i++) {
cin >> allocation_time[i] >> staff_id[i];
if(allocation_time[i] == -1 || staff_id[i] == -1) {
assert(allocation_time[i] == staff_id[i]);
score = score + (entry[i] - 1050) * happiness[i] * 0.1;
continue;
}
assert(staff_id[i] >= 1 && staff_id[i] <= k);
assert(allocation_time[i] >= entry[i] && allocation_time[i] <= 1050 - req_time[i]);
score = score + (entry[i] + wait[i] - allocation_time[i] - req_time[i]) * happiness[i] * 100;
status.push_back({{allocation_time[i] , staff_id[i]} , i });
}
sort(status.begin() , status.end());
for(int i = 0; i < status.size(); i++) {
int staff_id = status[i].first.second;
int alloc_time = status[i].first.first;
int user_id = status[i].second;
assert(busy[staff_id] <= alloc_time);
busy[staff_id] = alloc_time + req_time[user_id];
}
cout << (score+(long long)(5e6));
}
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