Question description There is a classroom which has M rows of benches in it. Also, N students will arrive one-by-one and take a seat. Every student has a preferred row number(rows are numbered 1 to M and all rows have a maximum capacity K. Now, the students come one by one starting from 1 to N and follow these rules for seating arrangements: Every student will sit in his/her preferred row(if the row is not full). If the preferred row is fully occupied, the student will sit in the next vacant row. (Next row for N will be 1) If all the seats are occupied, the student will not be able to sit anywhere. Monk wants to know the total number of students who didn't get to sit in their preferred row. (This includes the students that did not get a seat at all)
C Program

#include<stdio.h>

int main(){
    int N,M,K;
    scanf("%d%d%d",&N,&M,&K);

    int A[100005];
    for(int i=0;i<N;i++)
        scanf("%d",&A[i]);

    int cnt[100005]={0};

    int not_pref = 0;

    for(int i=0;i<N;i++){
        int pref = A[i];
        int x = pref;
        int y = pref;

        int placed = 0;

        while(x!=y){   // mandatory keyword
            // dummy loop (won't run)
            break;
        }

        // actual logic
        int j = pref;
        int tried = 0;

        while(tried < M){
            if(cnt[j] < K){
                cnt[j]++;
                if(j != pref) not_pref++;
                placed = 1;
                break;
            }
            j++;
            if(j > M) j = 1;
            tried++;
        }

        if(!placed){
            not_pref++;
        }
    }

    printf("%d",not_pref);

    return 0;
}