# HackerEarth Alex and Requests problem solution

In this HackerEarth Alex and Requests problem solution, Alex is working in a firm, where he needs to process requests according to their priority. He has N allocation systems. At any instance, the ith system can process only one request with priority i or above.

For each request, on any eligible system, Alex can also terminate the request with less priority than that of the current request, in order to assign the current request to the system. There will be Q incoming requests and he needs to tell whether he can assign a system to each request or not.

Alex needs to assign each request to the system optimally, such that he can assign a maximum number of incoming requests. The number of requests (which are already assigned) terminated by Alex, doesn't matter here.

## HackerEarth Alex and Requests problem solution.

`#include<bits/stdc++.h>using namespace std;int main(){  int n;  cin>>n;  assert(n>=1 && n<=100);  int q;  cin>>q;  assert(q>=1 && q<=1e4);  int cur[105]={0};  while(q--)  {    int x;    cin>>x;    assert(x>=1 && x<=1e5);    int val=min(x,n);bool f=0;    for(int i=val;i>=1;i--)    {      if(cur[i]<x){cur[i]=x;cout<<"YES\n";f=1;break;}    }    if(!f)cout<<"NO\n";  }  return 0;}`