#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e10;
vector <ll> T;
ll k = 1;
void build(vector <ll> a){
ll n = a.size();
while (k < n)k *= 2;
T.resize(2*k);
for (int i = 0; i < n; i++)T[i+k] = a[i];
for (int i = n; i < k; i++)T[i+k] = INF;
for (int i = k-1; i > 0; i--)T[i] = min(T[2*i], T[2*i+1]);
}
void reset(vector <ll> a){
ll n = a.size();
for (int i = 0; i < n; i++)T[i+k] = a[i];
for (int i = n; i < k; i++)T[i+k] = INF;
for (int i = k-1; i > 0; i--)T[i] = min(T[2*i], T[2*i+1]);
}
void update(ll x, ll v){
x += k; T[x] += v; x >>= 1;
for (; x; x >>= 1){
T[x] = min(T[2*x], T[2*x+1]);
}
}
int main(){
ll n, K, r; cin >> n >> K >> r;
vector <ll> v(n), aa(K, 0);
for (int i = 0; i < n; i++)cin >> v[i];
for (int i = 0; i < r; i++){
ll a, b; cin >> a >> b;
aa[a] = -b;
}
build(aa);
ll s = 1, e = n+1, m, M = -1;
while (e > s){
m = (e+s)/2;
for (int i = 0; i < m; i++)update(v[i], 1);
for (int i = m; i < n; i++){
if (T[1] >= 0){M = m; break;}
update(v[i-m], -1); update(v[i], 1);
}
if (T[1] >= 0)M = m;
if (M == m)e = m;
else s = m+1;
reset(aa);
}
if (M == -1)cout << "impossible";
else cout << M;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
372 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
368 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
2232 KB |
Output is correct |
2 |
Correct |
58 ms |
2252 KB |
Output is correct |
3 |
Correct |
44 ms |
2260 KB |
Output is correct |
4 |
Correct |
69 ms |
2248 KB |
Output is correct |
5 |
Correct |
260 ms |
6308 KB |
Output is correct |
6 |
Correct |
71 ms |
2252 KB |
Output is correct |
7 |
Correct |
81 ms |
2424 KB |
Output is correct |
8 |
Correct |
369 ms |
10364 KB |
Output is correct |
9 |
Correct |
166 ms |
3076 KB |
Output is correct |
10 |
Correct |
79 ms |
2260 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
4 ms |
444 KB |
Output is correct |
14 |
Correct |
3 ms |
448 KB |
Output is correct |
15 |
Correct |
3 ms |
320 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
300 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
300 KB |
Output is correct |
23 |
Correct |
1 ms |
304 KB |
Output is correct |
24 |
Correct |
1 ms |
304 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
237 ms |
6936 KB |
Output is correct |
2 |
Correct |
247 ms |
5432 KB |
Output is correct |
3 |
Correct |
242 ms |
5128 KB |
Output is correct |
4 |
Correct |
27 ms |
2260 KB |
Output is correct |
5 |
Correct |
271 ms |
7644 KB |
Output is correct |
6 |
Correct |
404 ms |
10880 KB |
Output is correct |
7 |
Correct |
184 ms |
3128 KB |
Output is correct |
8 |
Correct |
223 ms |
3808 KB |
Output is correct |
9 |
Correct |
72 ms |
2248 KB |
Output is correct |
10 |
Correct |
58 ms |
2248 KB |
Output is correct |
11 |
Correct |
47 ms |
2288 KB |
Output is correct |
12 |
Correct |
67 ms |
2276 KB |
Output is correct |
13 |
Correct |
252 ms |
6232 KB |
Output is correct |
14 |
Correct |
63 ms |
2264 KB |
Output is correct |
15 |
Correct |
81 ms |
2432 KB |
Output is correct |
16 |
Correct |
378 ms |
10316 KB |
Output is correct |
17 |
Correct |
160 ms |
3020 KB |
Output is correct |
18 |
Correct |
87 ms |
2236 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
4 ms |
340 KB |
Output is correct |
22 |
Correct |
4 ms |
468 KB |
Output is correct |
23 |
Correct |
3 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
300 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |