/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;
int n, k, ss, a[N], dp[N], arr[N];
multiset<int> s;
vector<bool> is(N);
void solve(){
cin >> n >> k >> ss;
for(int i = 1; i <= n; ++i) cin >> a[i];
for(int i = 0; i <= n; ++i) dp[i] = 0;
for(int i = 1; i <= ss; ++i){
int x, c; cin >> x >> c;
dp[x] -= c;
s.insert(-c);
is[x] = 1;
}
int best = MOD, l = 1;
for(int i = 1; i <= n; ++i){
if(!is[a[i]]) continue;
s.erase(s.find(dp[a[i]]));
dp[a[i]]++;
s.insert(dp[a[i]]);
while(!is[a[l]] || dp[a[l]] > 0){
if(!is[a[l]]){
l++;
continue;
}
s.erase(s.find(dp[a[l]]));
dp[a[l]]--;
s.insert(dp[a[l]]);
l++;
}
if((*s.begin()) >= 0) best = min(best, i - l + 1);
}
if(best == MOD) cout << "impossible";
else cout << best;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
cout << '\n';
}
return 0;
}
Compilation message
dna.cpp: In function 'int main()':
dna.cpp:61:16: warning: unused variable 'aa' [-Wunused-variable]
61 | int T = 1, aa;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
468 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
2312 KB |
Output is correct |
2 |
Correct |
20 ms |
2312 KB |
Output is correct |
3 |
Correct |
25 ms |
2388 KB |
Output is correct |
4 |
Correct |
24 ms |
2364 KB |
Output is correct |
5 |
Correct |
15 ms |
3144 KB |
Output is correct |
6 |
Correct |
25 ms |
2348 KB |
Output is correct |
7 |
Correct |
14 ms |
2564 KB |
Output is correct |
8 |
Correct |
17 ms |
3276 KB |
Output is correct |
9 |
Correct |
14 ms |
2904 KB |
Output is correct |
10 |
Correct |
33 ms |
2388 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
456 KB |
Output is correct |
23 |
Correct |
1 ms |
456 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
7532 KB |
Output is correct |
2 |
Correct |
101 ms |
6348 KB |
Output is correct |
3 |
Correct |
44 ms |
4152 KB |
Output is correct |
4 |
Correct |
21 ms |
2436 KB |
Output is correct |
5 |
Correct |
103 ms |
7848 KB |
Output is correct |
6 |
Correct |
78 ms |
8812 KB |
Output is correct |
7 |
Correct |
63 ms |
3380 KB |
Output is correct |
8 |
Correct |
74 ms |
3924 KB |
Output is correct |
9 |
Correct |
24 ms |
2316 KB |
Output is correct |
10 |
Correct |
22 ms |
2388 KB |
Output is correct |
11 |
Correct |
26 ms |
2448 KB |
Output is correct |
12 |
Correct |
34 ms |
2400 KB |
Output is correct |
13 |
Correct |
17 ms |
3112 KB |
Output is correct |
14 |
Correct |
25 ms |
2388 KB |
Output is correct |
15 |
Correct |
13 ms |
2516 KB |
Output is correct |
16 |
Correct |
17 ms |
3196 KB |
Output is correct |
17 |
Correct |
14 ms |
2900 KB |
Output is correct |
18 |
Correct |
32 ms |
2340 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
0 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
0 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
0 ms |
452 KB |
Output is correct |