이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
const ll N = 200069;
const ll mod = 1e9 + 7;
int tc;
ll n, k, r;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll i, j;
cin >> n >> k >> r;
ll pref[n+1][k+1];
memset(pref, 0, sizeof(pref));
for(i = 1; i <= n; i++)
{
for(j = 0; j < k; j++) pref[i][j] = pref[i-1][j];
ll x;
cin >> x;
++pref[i][x];
}
ll need[k+1];
memset(need, 0, sizeof(need));
bool bisa = 1;
ll sm = 0;
for(i = 1; i <= r; i++)
{
ll x, y;
cin >> x >> y;
need[x] = y;
sm += y;
if(need[x] > pref[n][x])
{
bisa = 0;
}
}
if(!bisa)
{
cout << "impossible" << '\n';
return 0;
}
ll ans = n;
for(i = sm; i <= n; i++)
{
ll cn = 0;
for(j = 0; j < k; j++) cn += pref[i][j] >= need[j];
if(cn == k)
{
ll l = 0, r = i;
while(l <= r)
{
ll mid = (l + r)/2;
ll res = 0;
for(j = 0; j < k; j++) res += pref[i][j] - pref[mid][j] >= need[j];
if(res == k)
{
ans = min(ans, i - mid);
l = mid + 1;
}
else r = mid - 1;
}
}
}
cout << ans << '\n';
}
| # | 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... |