#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
const ll N = 200069;
const ll mod = 1e9 + 7;
int tc;
ll n, k, r;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll i, j;
cin >> n >> k >> r;
ll pref[n+1][k+1];
memset(pref, 0, sizeof(pref));
for(i = 1; i <= n; i++)
{
for(j = 0; j < k; j++) pref[i][j] = pref[i-1][j];
ll x;
cin >> x;
++pref[i][x];
}
ll need[k+1];
memset(need, 0, sizeof(need));
bool bisa = 1;
ll sm = 0;
for(i = 1; i <= r; i++)
{
ll x, y;
cin >> x >> y;
need[x] = y;
sm += y;
if(need[x] > pref[n][x])
{
bisa = 0;
}
}
if(!bisa)
{
cout << "impossible" << '\n';
return 0;
}
ll ans = n;
for(i = sm; i <= n; i++)
{
ll cn = 0;
for(j = 0; j < k; j++) cn += pref[i][j] >= need[j];
if(cn == k)
{
ll l = 0, r = i;
while(l <= r)
{
ll mid = (l + r)/2;
ll res = 0;
for(j = 0; j < k; j++) res += pref[i][j] - pref[mid][j] >= need[j];
if(res == k)
{
ans = min(ans, i - mid);
l = mid + 1;
}
else r = mid - 1;
}
}
}
cout << ans << '\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 |
344 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 |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
105 ms |
78764 KB |
Output is correct |
4 |
Correct |
94 ms |
125788 KB |
Output is correct |
5 |
Correct |
66 ms |
50512 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
456 KB |
Output is correct |
15 |
Correct |
0 ms |
360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
18040 KB |
Output is correct |
2 |
Correct |
21 ms |
5468 KB |
Output is correct |
3 |
Correct |
56 ms |
19548 KB |
Output is correct |
4 |
Correct |
47 ms |
19544 KB |
Output is correct |
5 |
Runtime error |
796 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
499 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |