Jishan's Log 6: Codeforces 158A solution
Codeforces 158A: Next Round
What the problem wants?
The problem states that there are a n scores and from those scores we must take the score of the kth position as the passing mark. If a score is greater than or equal to the kth position and if it is greater than 0, then the candidate passes.
How to solve it?
Algorithm:
1) take the n and k inputs
2) for i=0 => n (1 => n), we read the integers and store it in an array. We then get the value of the kth position and check if the value in the array is greater than k or not & if it is greater than 0. If it is, we increment a counter. Finally we print it.
The Code:
***NOTE: Since I've taken the array from 0 => n, that's why I've taken the k-1 position. If you start from 1, you can take k only
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
fastio;
int n, k; scanf("%d%d", &n, &k);
int scores[n];
for(int i=0; i<n; i++)
{
int x; scanf("%d", &x);
scores[i] = x;
}
int passing_score = scores[k-1]; int participants_passed = 0;
for(int i=0; i<n; i++)
{
if(scores[i] >= passing_score && scores[i] > 0) {participants_passed++;}
}
printf("%d\n", participants_passed);
}
Comments
Post a Comment