Problem Statement
You are the hiring manager of a startup and you are interviewing N candidates, each having an ID numbered from 1 to N . Each candidate has a score Ai calculated from their HackerRank tests. You start with patience P and lose patience X after each interview.
One by one candidates enter your room in the sequence of their ID numbers. To save time you decide to give a rating of (P×Ai) . In the end you hire the candidate with maximum rating. Print the ID of this candidate.
NOTE: It is guaranteed that a unique ID gets selected.
NOTE: It is guaranteed that a unique ID gets selected.
Input Format
The first line begins with3 space-separated integers, N , P , and X .
The next line contains an arrayA[] , containing the scores of the N candidates.
The first line begins with
The next line contains an array
Constraints
1≤N≤105
1≤P≤109
1≤X≤100
1≤Ai≤109
Output Format
Output the ID of the Applicant who get selected.
Output the ID of the Applicant who get selected.
NOTE: ID's are numbered from 1 to N .
Sample Input
4 94 8
8 6 4 6
Sample Output
1
Explanation
Rating for Applicant 1 is94×8=752
Chance for Applicant 2 is86×6=516
Chance for Applicant 3 is78×4=312
Chance for Applicant 4 is70×6=420
Rating for Applicant 1 is
Chance for Applicant 2 is
Chance for Applicant 3 is
Chance for Applicant 4 is
So ID 1 gets selected.
MY SOLUTION:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
unsigned long int n,p;
unsigned int x,i;
scanf("%ld %ld %d",&n,&p,&x);
unsigned long int ans,pos;
for(i=0;i<n;i++)
{
unsigned long int value;
scanf("%ld",&value);
value=value*p;
p=p-x;
if(i==0)
{
ans=value;
pos=i+1;
}
else if(ans<value)
{
ans=value;
pos=i+1;
}
}
printf("%ld",pos);
return 0;
}