#include <iostream>
#include <vector>
#include <map>
#include <climits>
#define int long long
using namespace std;
signed main() {
int n, k, r, res = LLONG_MAX, ri = -1;
bool ok;
map<int,int> c;
cin >> n >> k >> r;
vector<int> a(n), sum(r);
vector<pair<int,int>> b(r);
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < r; i++) {
cin >> b[i].first >> b[i].second;
c[b[i].first] = i+1;
}
//find start
while(true) {
if(ri == n-1) {
cout << "impossible\n";
return 0;
}
ri++;
if(c[a[ri]]) {
sum[c[a[ri]]-1]++;
ok = true;
for(int i = 0; i < r; i++) {
if(sum[i] < b[i].second) {
ok = false;
break;
}
}
if(ok) break;
}
}
//start
res = ri+1;
for(int i = 0; i < n; i++) {
if(c[a[i]]) {
sum[c[a[i]]-1]--;
ok = true;
while(sum[c[a[i]]-1] < b[c[a[i]]-1].second) {
if(ri == n-1) {
ok = false;
break;
}
ri++;
if(c[a[ri]]) sum[c[a[ri]]-1]++;
}
if(!ok) break;
}
res = min(res, ri-i);
}
cout << res << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
1880 KB |
Output is correct |
2 |
Correct |
26 ms |
1880 KB |
Output is correct |
3 |
Correct |
34 ms |
1884 KB |
Output is correct |
4 |
Correct |
29 ms |
1884 KB |
Output is correct |
5 |
Correct |
99 ms |
6996 KB |
Output is correct |
6 |
Correct |
26 ms |
1884 KB |
Output is correct |
7 |
Correct |
33 ms |
1884 KB |
Output is correct |
8 |
Correct |
132 ms |
14288 KB |
Output is correct |
9 |
Correct |
70 ms |
2384 KB |
Output is correct |
10 |
Correct |
31 ms |
1884 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
548 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
198 ms |
8792 KB |
Output is correct |
2 |
Correct |
174 ms |
8764 KB |
Output is correct |
3 |
Correct |
121 ms |
7508 KB |
Output is correct |
4 |
Correct |
26 ms |
2396 KB |
Output is correct |
5 |
Correct |
146 ms |
12116 KB |
Output is correct |
6 |
Correct |
196 ms |
17488 KB |
Output is correct |
7 |
Correct |
72 ms |
3572 KB |
Output is correct |
8 |
Correct |
115 ms |
4824 KB |
Output is correct |
9 |
Correct |
27 ms |
2392 KB |
Output is correct |
10 |
Correct |
26 ms |
2400 KB |
Output is correct |
11 |
Correct |
32 ms |
2244 KB |
Output is correct |
12 |
Correct |
30 ms |
2396 KB |
Output is correct |
13 |
Correct |
96 ms |
8016 KB |
Output is correct |
14 |
Correct |
27 ms |
2392 KB |
Output is correct |
15 |
Correct |
33 ms |
2556 KB |
Output is correct |
16 |
Correct |
131 ms |
15552 KB |
Output is correct |
17 |
Correct |
67 ms |
3412 KB |
Output is correct |
18 |
Correct |
32 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
436 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |