#include <iostream>
#include <iomanip>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <random>
#include <sstream>
#include <string.h>
#include <assert.h>
#include <limits.h>
using namespace std;
#define fi first
#define se second
#define int long long
#define pb push_back
typedef pair<int,int> ii;
const int INF = 1e18;
map<int, int> cons;
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, k, r; cin >> n >> k >> r;
vector<int> a(n + 2); for (int i=1; i<=n; i++) cin >> a[i];
for (int i=1; i<=r; i++) {
int b, q; cin >> b >> q;
cons[b] = q;
}
queue<int> cur;
int cnt = 0; int ans = INF;
map<int, int> have;
for (int i=1; i<=n; i++) {
// cout << ">> " << a[i] << " " << have[a[i]] << " " << cons[a[i]] << '\n';
cur.push(a[i]), have[a[i]]++;
if (have[a[i]] == cons[a[i]]) cnt++;
if (cnt == r)
ans = min(ans, (int)cur.size());
while(!cur.empty() && have[cur.front()] > cons[cur.front()]) {
have[cur.front()]--; cur.pop();
}
if (cnt == r)
ans = min(ans, (int)cur.size());
}
if (ans == INF) cout << "impossible";
else cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
376 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 |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
1028 KB |
Output is correct |
5 |
Correct |
2 ms |
604 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 |
348 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 |
12 ms |
2648 KB |
Output is correct |
2 |
Correct |
11 ms |
2660 KB |
Output is correct |
3 |
Correct |
14 ms |
2468 KB |
Output is correct |
4 |
Correct |
13 ms |
2908 KB |
Output is correct |
5 |
Correct |
150 ms |
13908 KB |
Output is correct |
6 |
Correct |
18 ms |
3924 KB |
Output is correct |
7 |
Correct |
20 ms |
4096 KB |
Output is correct |
8 |
Correct |
173 ms |
29012 KB |
Output is correct |
9 |
Correct |
94 ms |
4616 KB |
Output is correct |
10 |
Correct |
16 ms |
2908 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 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 |
600 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
197 ms |
12624 KB |
Output is correct |
2 |
Correct |
177 ms |
11528 KB |
Output is correct |
3 |
Correct |
156 ms |
11224 KB |
Output is correct |
4 |
Correct |
10 ms |
2392 KB |
Output is correct |
5 |
Correct |
181 ms |
18180 KB |
Output is correct |
6 |
Correct |
285 ms |
27688 KB |
Output is correct |
7 |
Correct |
78 ms |
5500 KB |
Output is correct |
8 |
Correct |
127 ms |
6988 KB |
Output is correct |
9 |
Correct |
12 ms |
3164 KB |
Output is correct |
10 |
Correct |
10 ms |
2660 KB |
Output is correct |
11 |
Correct |
14 ms |
2392 KB |
Output is correct |
12 |
Correct |
13 ms |
2908 KB |
Output is correct |
13 |
Correct |
138 ms |
13860 KB |
Output is correct |
14 |
Correct |
14 ms |
3928 KB |
Output is correct |
15 |
Correct |
18 ms |
4176 KB |
Output is correct |
16 |
Correct |
164 ms |
28928 KB |
Output is correct |
17 |
Correct |
94 ms |
4540 KB |
Output is correct |
18 |
Correct |
20 ms |
2904 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
724 KB |
Output is correct |
22 |
Correct |
2 ms |
860 KB |
Output is correct |
23 |
Correct |
2 ms |
604 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 |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
460 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |