Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- #include <iostream>
- #
- #include <string>
- #
- #include <cstring>
- #
- #include <vector>
- #
- #include <cmath>
- #
- #include <map>
- #
- #include <algorithm>
- #
- #include <climits>
- #
- using namespace std;
- #
- int S[1000005], cnt[1000005];
- #
- int main() {
- #
- int n,A,B,lp = 0,targ,cur = 0,ans = INT_MAX;
- #
- scanf("%d%d%d",&n,&A,&B);
- #
- targ = B-A+1;
- #
- if(targ > n) {
- #
- printf("-1\n");
- #
- return 0;
- #
- }
- #
- for(int rp=0;rp<n;++rp) {
- #
- scanf("%d",&S[rp]);
- #
- if(S[rp] < A || S[rp] > B) {
- #
- while(lp < rp) {
- #
- --cnt[S[lp]-A];
- #
- ++lp;
- #
- }
- #
- ++lp;
- #
- cur = 0;
- #
- continue;
- #
- }
- #
- int& v = cnt[S[rp]-A];
- #
- ++v;
- #
- if(v == 1) ++cur;
- #
- while(cur == targ) {
- #
- ans = min(ans,rp-lp+1);
- #
- int& k = cnt[S[lp]-A];
- #
- --k;
- #
- if(!k) --cur;
- #
- ++lp;
- #
- }
- #
- }
- #
- if(ans == INT_MAX) printf("-1\n");
- #
- else printf("%d\n",ans);
- #
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement