SER12


TEST CASE 1 

INPUT
5 2 2
1 1 2 1 1
OUTPUT
2

TEST CASE 2 

INPUT
7 2 2
1 1 2 1 1 7 1
OUTPUT
3


#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int N,M,K;
    cin>>N>>M>>K;
    int x;
    int occupied[M+1], nextrow[M+1], ans=0;
    for(int i=1; i<=M; i++)
    {
        nextrow[i]=i;
        occupied[i]=0;
    }
    bool flag=0;
    for(int i=0; i<N; i++)
    {
        cin>>x;
        if(!flag)
        {
            if(occupied[x]<K)
            {
                occupied[x]++;
            }
            else
            {
                if(occupied[nextrow[x]]<K)
                {
                    occupied[nextrow[x]]++;
                    ans++;
                }
                else
                {
                    int y=(nextrow[x])%N+1;
                    while(true)
                    {
                        if(y==x)
                        {
                            flag=1;
                            ans++;
                            break;
                        }
                        else
                        {
                            if(occupied[y]<K)
                            {
                                occupied[y]++;
                                ans++;
                                while(x!=y)
                                {
                                    nextrow[x]=y;
                                    x=(x)%N+1;
                                }
                                break;
                            }
                            else
                            {
                                y=y%N+1;
                            }
                        }
                    }
               }
            }
        }
        else
        {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Comments

  1. Hotel Casino de Monte-Carlo Casino - Mapyro
    Hotel Casino de Monte-Carlo is 양산 출장샵 a 4-star hotel with 용인 출장마사지 2,000 guest rooms and 수원 출장안마 villas located in the center. The Casino is situated 양산 출장안마 within 6 km (15 mi) 서귀포 출장안마 of Casino de Monte-Carlo,

    ReplyDelete

Post a Comment

Popular posts from this blog

AR1

AR15