This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///*** Sown_Vipro ***///
/// ->NHI QUOC GIA<- ///
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
#define F first
#define S second
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define REP(i, a, b) for(int i = a; i >= b; --i)
#define all(s) s.begin(), s.end()
#define szz(s) (s.size())
const string NAME = "sown";
const int N = 1e6 + 5, MAX = 1e6, oo = 1e9 + 5, MOD = 1e9 + 7;
void maxi(int &x, int y){ if(x < y) x = y; }
void mini(int &x, int y){ if(x > y) x = y; };
void add(int &x, int y){ x += y; x += MOD * (x < 0); x -= MOD * (x >= MOD); };
int n, k, r, res;
int c[N], d[N], a[N];
void solve(){
cin >> n >> k >> r;
FOR(i, 1, n){
cin >> a[i];
}
int i = 1, j = 1;
FOR(j, 1, r){
int b, q; cin >> b >> q;
c[b] = q;
while(i <= n + 1 && d[b] < c[b]){
++d[a[i]];
++i;
}
}
if(i > n + 1){
cout << "impossible"; return;
}
while(d[a[j]] > c[a[j]]){
--d[a[j]]; ++j;
}
res = i - j;
for(i; i <= n; ++i){
++d[a[i]];
while(d[a[j]] > c[a[j]]){
--d[a[j]]; ++j;
}
res = min(res, i - j + 1);
}
cout << res;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// if(fopen((NAME + ".inp").c_str(), "r")){
// freopen((NAME + ".inp").c_str(), "r", stdin);
// freopen((NAME + ".out").c_str(), "w", stdout);
// }
int t = 1;
// cin >> t;
while(t--){
solve();
}
}
Compilation message (stderr)
dna.cpp: In function 'void solve()':
dna.cpp:47:9: warning: statement has no effect [-Wunused-value]
47 | for(i; i <= n; ++i){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |