이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define nikah ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll maxn = 2e5+7;
using namespace std;
ll n,k,r;
ll a[maxn];
map<ll,ll>m,m1,m2;
int main () {
nikah
cin>>n>>k>>r;
for (ll i=1; i<=n; i++) {
cin>>a[i];
m1[a[i]]++; m2[a[i]]++;
}
bool cek = 0;
for (ll i=1; i<=r; i++) {
ll x,y; cin>>x>>y;
m[x] = y;
if (m1[x] < m[x]) {
cek = 1;
}
}
if (cek) {
cout<<"impossible"<<endl;
} else {
ll l = 1, r = n;
while (l <= r) {
if (m1[a[l]] == m[a[l]]) {
break;
}
m1[a[l]]--;
l++;
}
while (l <= r) {
if (m1[a[r]] == m[a[r]]) {
break;
}
m1[a[r]]--;
r--;
}
ll ans = r-l+1;
l = 1, r = n;
while (l <= r) {
if (m2[a[r]] == m[a[r]]) {
break;
}
m2[a[r]]--;
r--;
}
while (l <= r) {
if (m2[a[l]] == m[a[l]]) {
break;
}
m2[a[l]]--;
l++;
}
ans = min(ans, r - l + 1);
cout<<ans<<endl;
}
}
| # | 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... |