Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- constexpr int NMAX = 2e5 + 3;
- int na, nb, a[NMAX], b[NMAX];
- void read() {
- cin >> na >> nb;
- for (int i = 1; i <= na; i++) {
- cin >> a[i];
- }
- for (int i = 1; i <= nb; i++) {
- cin >> b[i];
- }
- }
- int solve(int start, int finish) {
- int ans = 0;
- unordered_map<int, int> fr;
- for (int i = start; i <= finish; i++) {
- fr[a[i]]++;
- }
- for (int i = 1; i <= nb; i++) {
- if (fr[i] > b[i]) {
- ans++;
- } else if (fr[i] != b[i]) {
- return INT_MAX;
- }
- }
- return ans;
- }
- signed main() {
- read();
- int ans = INT_MAX;
- for (int i = 1; i <= na; i++) {
- for (int j = i; j <= na; j++) {
- int currAns = solve(i, j);
- ans = min(ans, currAns);
- }
- }
- cout << ans << endl;//*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement