#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pairll pair<ll,ll>
#define lpairll pair<ll,pairll>
#define repp(i,a,b) for (ll i = a; i <= b; i++)
#define repz(i,a,b) for (ll i = a; i < b; i++)
#define repm(i,a,b) for (ll i = a; i >= b; i--)
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
const ll N = 2e5+5, MOD = 1e9+7;
ll tc = 1, n, m, ar[N], br[N], need[N], cr[N], cnt[N];
ll x, y, k;
string s, s1, s2, ye = "YES", no = "NO";
vector<pairll> v;
bool pos(ll key){
ll rem = k;
memset(cnt,0,sizeof(cnt));
repp(i,1,key){
cnt[ar[i]]++;
if (cnt[ar[i]] == need[ar[i]]) rem--;
if (rem == 0) return 1;
}
repp(i,key+1,n){
cnt[ar[i-key]]--;
if (cnt[ar[i-key]] == need[ar[i-key]]-1) rem++;
cnt[ar[i]]++;
if (cnt[ar[i]] == need[ar[i]]) rem--;
if (rem == 0) return 1;
}
return 0;
}
void input(){
cin >> n >> m >> k;
repp(i,1,n) cin >> ar[i];
repp(i,1,k){
cin >> x >> y;
br[i] = x, cr[i] = y;
need[x] = y;
}
}
void solve(){
ll l = 1, r = n, ret = -1;
while(l <= r){
ll md = (l+r)/2;
if (pos(md)){
r = md-1;
ret = md;
}
else l = md+1;
}
if (ret == -1) cout << "impossible\n";
else cout << ret << "\n";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
//cin >> tc;
while(tc--){
input();
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1876 KB |
Output is correct |
8 |
Correct |
1 ms |
1860 KB |
Output is correct |
9 |
Correct |
2 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
2 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
2 ms |
1876 KB |
Output is correct |
6 |
Correct |
2 ms |
1864 KB |
Output is correct |
7 |
Correct |
2 ms |
1876 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1860 KB |
Output is correct |
10 |
Correct |
2 ms |
1860 KB |
Output is correct |
11 |
Correct |
1 ms |
1860 KB |
Output is correct |
12 |
Correct |
1 ms |
1876 KB |
Output is correct |
13 |
Correct |
1 ms |
1876 KB |
Output is correct |
14 |
Correct |
1 ms |
1876 KB |
Output is correct |
15 |
Correct |
2 ms |
1860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
3848 KB |
Output is correct |
2 |
Correct |
24 ms |
3772 KB |
Output is correct |
3 |
Correct |
17 ms |
3880 KB |
Output is correct |
4 |
Correct |
21 ms |
3796 KB |
Output is correct |
5 |
Correct |
34 ms |
4368 KB |
Output is correct |
6 |
Correct |
23 ms |
3872 KB |
Output is correct |
7 |
Correct |
23 ms |
3924 KB |
Output is correct |
8 |
Correct |
38 ms |
4324 KB |
Output is correct |
9 |
Correct |
28 ms |
4332 KB |
Output is correct |
10 |
Correct |
29 ms |
3756 KB |
Output is correct |
11 |
Correct |
2 ms |
1876 KB |
Output is correct |
12 |
Correct |
2 ms |
1872 KB |
Output is correct |
13 |
Correct |
2 ms |
1876 KB |
Output is correct |
14 |
Correct |
2 ms |
1904 KB |
Output is correct |
15 |
Correct |
2 ms |
1876 KB |
Output is correct |
16 |
Correct |
2 ms |
1876 KB |
Output is correct |
17 |
Correct |
1 ms |
1876 KB |
Output is correct |
18 |
Correct |
1 ms |
1876 KB |
Output is correct |
19 |
Correct |
2 ms |
1860 KB |
Output is correct |
20 |
Correct |
1 ms |
1868 KB |
Output is correct |
21 |
Correct |
2 ms |
1876 KB |
Output is correct |
22 |
Correct |
1 ms |
1876 KB |
Output is correct |
23 |
Correct |
2 ms |
1868 KB |
Output is correct |
24 |
Correct |
1 ms |
1876 KB |
Output is correct |
25 |
Correct |
1 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
6224 KB |
Output is correct |
2 |
Correct |
49 ms |
5756 KB |
Output is correct |
3 |
Correct |
44 ms |
5060 KB |
Output is correct |
4 |
Correct |
11 ms |
3792 KB |
Output is correct |
5 |
Correct |
42 ms |
6352 KB |
Output is correct |
6 |
Correct |
55 ms |
7288 KB |
Output is correct |
7 |
Correct |
31 ms |
4524 KB |
Output is correct |
8 |
Correct |
43 ms |
4748 KB |
Output is correct |
9 |
Correct |
30 ms |
3796 KB |
Output is correct |
10 |
Correct |
26 ms |
3792 KB |
Output is correct |
11 |
Correct |
16 ms |
3836 KB |
Output is correct |
12 |
Correct |
21 ms |
3796 KB |
Output is correct |
13 |
Correct |
30 ms |
4340 KB |
Output is correct |
14 |
Correct |
21 ms |
3796 KB |
Output is correct |
15 |
Correct |
23 ms |
3924 KB |
Output is correct |
16 |
Correct |
39 ms |
4268 KB |
Output is correct |
17 |
Correct |
30 ms |
4500 KB |
Output is correct |
18 |
Correct |
27 ms |
3844 KB |
Output is correct |
19 |
Correct |
2 ms |
1876 KB |
Output is correct |
20 |
Correct |
2 ms |
1876 KB |
Output is correct |
21 |
Correct |
2 ms |
1872 KB |
Output is correct |
22 |
Correct |
2 ms |
1872 KB |
Output is correct |
23 |
Correct |
3 ms |
1876 KB |
Output is correct |
24 |
Correct |
2 ms |
1868 KB |
Output is correct |
25 |
Correct |
1 ms |
1876 KB |
Output is correct |
26 |
Correct |
2 ms |
1876 KB |
Output is correct |
27 |
Correct |
2 ms |
1876 KB |
Output is correct |
28 |
Correct |
1 ms |
1948 KB |
Output is correct |
29 |
Correct |
1 ms |
1876 KB |
Output is correct |
30 |
Correct |
1 ms |
1876 KB |
Output is correct |
31 |
Correct |
1 ms |
1864 KB |
Output is correct |
32 |
Correct |
1 ms |
1876 KB |
Output is correct |
33 |
Correct |
1 ms |
1876 KB |
Output is correct |