#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, k, r;
cin>>n>>k>>r;
int l[n], sum[k]={0}, min=n+1, need[n]={0}, complete=0;
bool full[k] = {false};
for (int i=0; i<n; ++i)
{
cin>>l[i];
need[i]=1;
}
for (int i=0; i<r; ++i)
{
int a,b;
cin>>a>>b;
need[a]=b;
}
int left=0, right=0;
int change=1;
for (; right<n;)
{
if (change==0)
{
sum[l[left-1]]--;
if (need[l[left-1]]>sum[l[left-1]])
{
complete--;
}
}
else if (change==1)
{
sum[l[right]]++;
if (need[l[right]]==sum[l[right]])
{
complete++;
}
}
if (complete==k)
{
change=0;
left++;
if (right-left+2<min)
{
min=right-left+2;
}
}
else
{
right++;
change=1;
}
}
if (min>=n)
{
cout<<"impossible";
}
else
{
cout<<min<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |