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 Health of a person problem solution

YASH PAL, 31 July 2024
In this HackerEarth Health of a person problem solution There N people in your city. The jth person contains Aj health point. You are trying to make these people walk in your locality. You walk for M days. On an ith day, every walk decreases Bj health points of the person you are walking with. Also, on an ith day, you can only walk with the jth person if the person is still healthy and j is a multiple of i. You can walk with as many people as you can but you can walk with a specific person only once a day.
A person becomes unhealthy if their health point becomes less than or equal to 0. At the end of each day, their health points are restored to their original level if they are not unhealthy already. Your task is to determine the day in which the ith person becomes unhealthy or will remain healthy.
HackerEarth Health of a person problem solution

HackerEarth Health of a person problem solution.

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000009;

int t;
int n, m;

int anss[maxn], health[maxn], pwr[maxn];

int main()
{

cin >> t;
while(t--){

scanf("%d %d", &n, &m);
memset(anss, -1, sizeof(anss));
for(int i = 1; i <= n; i++) scanf("%d", &health[i]);

for(int i = 1; i <= m; i++){
int x;
scanf("%d", &x);
for(int j = i; j <= n; j += i) {
if(anss[j] != -1) continue;
if(health[j] <= x) anss[j] = i;
}
}

for(int i = 1; i <= n; i++) printf("%dn", anss[i]);

}

return 0;
}

second solution

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 17;
int col[maxn], a[maxn];
int main(){
ios::sync_with_stdio(0), cin.tie(0);
int t;
cin >> t;
for(int i = 0; i < t; i++){
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> a[i];
memset(col, -1, sizeof col);
for(int i = 1; i <= m; i++){
int b;
cin >> b;
for(int j = i; j <= n; j += i)
if(col[j] == -1 && a[j] - b <= 0)
col[j] = i;
}
for(int i = 1; i <= n; i++)
cout << col[i] << 'n';
}
}
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