Menu

Hackerearth – Akash and the Assignment

January 27, 2017 - Hackerearth

Language: C++

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long lol;
 
#define FI "inp.txt"
#define FO "out.txt"
const int MAXN = 5e4 + 5;
 
int N, Q;
char S[MAXN];
int cnt[MAXN][26];
int L, R, K;
 
int main() {
	scanf("%d%d", &N, &Q);
	scanf("%s", S + 1);
	memset(cnt[0], 0, sizeof cnt[0]);
	for (int i = 1; i <= N; ++i) {
		memcpy(cnt[i], cnt[i - 1], sizeof cnt[i]);
		++cnt[i][S[i] - 'a'];
	}
	while (Q--) {
		scanf("%d%d%d", &L, &R, &K);
		if (K > R - L + 1) {
			printf("Out of range\n");
			continue;
		}
		int i;
		for (i = 0; K > cnt[R][i] - cnt[L - 1][i] && i < 26; ++i) {
			K -= (cnt[R][i] - cnt[L - 1][i]);
		}		
		printf("%c\n", i + 'a');		
	}
	return 0;
}

(604)

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on VK

Author of this post : UnknownA AuthorA

Leave a Reply

Your email address will not be published. Required fields are marked *