#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define sst string
#define pb push_back
#define maxco 100000+5
#define lld long double
#define cha ios_base::sync_with_stdio(false);
#define ffl cout.flush();
#define phi acos(-1)
#define mr make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define pqin priority_queue<ll,vector<ll>,greater<>>
#define pqpair priority_queue<pair<ll,ll> ,vector<pair<ll,ll>>,greater<pair<ll,ll>>>
#define pqpair2 priority_queue<pair<pair<ll,ll>,pair<ll,ll>>,vector<pair<pi,pair<ll,ll>>>,greater<pair<pi,pair<ll,ll>>>>
#define INF 1000000009
#define MAXN 1000006
#define pii pair<ll,ll>
#define mod 998244353
ll a[MAXN];
ll n,k,r;
map<ll,ll> nd;
map<ll,ll> cnt;
int main(){
cin>>n>>k>>r;
REP(i,1,n){
cin>>a[i];
}
REP(i,1,r){
ll b,c;
cin>>b>>c;
nd[b]=c;
}
ll ans=1e18;
set<ll> st;
ll l=1;
for(ll i=1;i<=n;i++){
cnt[a[i]]++;
if(cnt[a[i]]==nd[a[i]] && nd[a[i]]>0){
st.insert(a[i]);
}
if(st.size()==r){
while(l<i && cnt[a[l]]>nd[a[l]]){
cnt[a[l]]--;
l++;
}
ans=min(ans,i-l+1);
}
}
if(ans==1e18)cout<<-1<<endl;
else cout<<ans<<endl;
}
Compilation message
dna.cpp: In function 'int main()':
dna.cpp:46:21: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
46 | if(st.size()==r){
| ~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
860 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 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
2652 KB |
Output is correct |
2 |
Correct |
16 ms |
2664 KB |
Output is correct |
3 |
Correct |
19 ms |
2664 KB |
Output is correct |
4 |
Correct |
17 ms |
2652 KB |
Output is correct |
5 |
Correct |
136 ms |
12444 KB |
Output is correct |
6 |
Correct |
19 ms |
2648 KB |
Output is correct |
7 |
Incorrect |
23 ms |
2660 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
204 ms |
16528 KB |
Output is correct |
2 |
Correct |
179 ms |
12880 KB |
Output is correct |
3 |
Correct |
151 ms |
10880 KB |
Output is correct |
4 |
Correct |
15 ms |
2648 KB |
Output is correct |
5 |
Incorrect |
167 ms |
14912 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |