This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, k, r;
cin>>n>>k>>r;
int a[n], b[k+1], visited[k+1];
memset(visited, 0, sizeof(visited));
set<int>barani;
for(int i=0; i<k+1; i++)
b[i]=-1;
for(int i=0; i<n; i++)
{
cin>>a[i];
}
for(int i=0; i<r; i++)
{
int aa, bb;
cin>>aa>>bb;
b[aa]=bb;
barani.insert(aa);
}
int manjak=barani.size(), rez=INT_MAX;
for(int r=0, l=0; r<n; r++)
{
if(barani.find(a[r])!=barani.end())
{
visited[a[r]]++;
if(visited[a[r]]==b[a[r]])
{
manjak--;
}
}
if(manjak==0)
{
while(l<=r && manjak==0)
{
if(barani.find(a[l])!=barani.end())
{
visited[a[l]]--;
if(visited[a[l]]==b[a[l]]-1)
{
manjak++;
}
}
l++;
}
if(manjak>0)
rez=min(r-l+2, rez);
}
}
if(rez==INT_MAX)
cout<<"impossible";
else
cout<<rez;
return 0;
}
# | 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... |