#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define yes "YES"
#define no "NO"
#define bigg INT_MAX
#define debug(x) cout<<(#x)<<" = " <<x<<endl;
#define all(x) x.begin(),x.end()
#define sz size()
#define nn '\n'
#define mms(x,y) memset(x,y,sizeof(x))
#define forr(i,j,n) for (int i=j; i<n; i++)
#define forn(i,j,n) for (int i=j; i>n; i--)
#define fi first
#define se second
#define la "LA"
#define cinn(x,y) for(int i=0; i<y; i++) cin>>x[i];
#define pii pair<int,int>
signed main()
{
// #ifndef LOCAL
// freopen("lifeguards.in","r",stdin);
// freopen("lifeguards.out","w", stdout);
// #endif
fast
int n,k,r;
cin>>n >>k >>r;
int a[n];
forr(i,0,n)
{
cin>>a[i];
}
int freq[k]={ };
bool req[k]={ };
forr(i,0,r)
{
int x,y;
cin>>x >>y;
freq[x]=y;
req[x]=1;
}
int j=0;
int c=r;
int ans=bigg;
forr(i,0,n)
{
int x=a[i];
if (c==0)
{
for(;j<=i;j++)
{
if (req[a[j]] && freq[a[j]]==0) break;
freq[a[j]]++;
}
ans=min(ans,i-j);
}
else{
// if (freq[x])
// {
freq[x]--;
if (freq[x]==0) c--;
//freq[x]=-1;
// }
}
}
if (ans==bigg) cout<<"impossible";
else cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |