Skip to content

Instantly share code, notes, and snippets.

@arashatt
Last active December 20, 2020 13:46
Show Gist options
  • Save arashatt/efebe3423e60832081b16ef32f43b8a2 to your computer and use it in GitHub Desktop.
Save arashatt/efebe3423e60832081b16ef32f43b8a2 to your computer and use it in GitHub Desktop.
تخمین رتبه
#include<iostream>
#include<queue>
#include<cassert>
using namespace std;
int main() {
queue<int>myQueue;
int n, k;
int temp;
scanf( "%d %d", &k, &n);
int MAX_K = 1000000000;
int* number = new int[MAX_K];
for (int i = 0; i < MAX_K; i++) {
number[i] = 0;
}
for (int i = 0; i < k; i++) {
scanf("%d", &temp);
myQueue.push(temp);
number[temp - 1]++;
}
int j = 0;
for (int i = 0; i < n - k; i++) {
j = 0; while (number[j] != 0){
assert(number[j]>=0);
j++;
}
myQueue.push(j + 1);
number[j]++;
number[myQueue.front() - 1]--;
myQueue.pop();
}
printf( "%d", myQueue.back());
delete[] number;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment