#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << " " <<
#define nl << "\n"
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n, k, r; cin >> n >> k >> r;
int a[n], b[k];
fill(b, b+k, -n);
for(int i=0; i<n; ++i) cin >> a[i];
for(int i=0, j; i<r; ++i) cin >> j >> b[j];
int i = 0, curr = n-r, ans = 1e18;
for(int j=0; j<n; ++j){
curr += --b[a[j]]==0;
while(i<j and b[a[i]] < 0) ++b[a[i++]];
if(curr==n) ans = min(ans, j-i+1);
}
if(ans==(int)1e18) cout << "impossible";
else cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
380 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
1900 KB |
Output is correct |
2 |
Correct |
18 ms |
1900 KB |
Output is correct |
3 |
Correct |
16 ms |
1900 KB |
Output is correct |
4 |
Correct |
15 ms |
1900 KB |
Output is correct |
5 |
Correct |
21 ms |
2540 KB |
Output is correct |
6 |
Correct |
17 ms |
1900 KB |
Output is correct |
7 |
Correct |
15 ms |
1900 KB |
Output is correct |
8 |
Correct |
24 ms |
3436 KB |
Output is correct |
9 |
Correct |
18 ms |
1900 KB |
Output is correct |
10 |
Correct |
17 ms |
1900 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
0 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
2668 KB |
Output is correct |
2 |
Correct |
30 ms |
2412 KB |
Output is correct |
3 |
Correct |
26 ms |
2412 KB |
Output is correct |
4 |
Correct |
16 ms |
1900 KB |
Output is correct |
5 |
Correct |
35 ms |
2668 KB |
Output is correct |
6 |
Correct |
39 ms |
3308 KB |
Output is correct |
7 |
Correct |
24 ms |
1900 KB |
Output is correct |
8 |
Correct |
30 ms |
2028 KB |
Output is correct |
9 |
Correct |
16 ms |
1900 KB |
Output is correct |
10 |
Correct |
16 ms |
1900 KB |
Output is correct |
11 |
Correct |
16 ms |
1900 KB |
Output is correct |
12 |
Correct |
15 ms |
1900 KB |
Output is correct |
13 |
Correct |
20 ms |
2540 KB |
Output is correct |
14 |
Correct |
14 ms |
1900 KB |
Output is correct |
15 |
Correct |
18 ms |
1900 KB |
Output is correct |
16 |
Correct |
29 ms |
3436 KB |
Output is correct |
17 |
Correct |
18 ms |
1900 KB |
Output is correct |
18 |
Correct |
18 ms |
1900 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |