Advertisement
STANAANDREY

hackathon: "omicron" 80p

Jan 24th, 2022
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. constexpr int NMAX = 2e5 + 3;
  4. int na, nb, a[NMAX], b[NMAX];
  5.  
  6. void read() {
  7.     cin >> na >> nb;
  8.     for (int i = 1; i <= na; i++) {
  9.         cin >> a[i];
  10.     }
  11.     for (int i = 1; i <= nb; i++) {
  12.         cin >> b[i];
  13.     }
  14. }
  15.  
  16. int solve(int start, int finish) {
  17.     int ans = 0;
  18.     unordered_map<int, int> fr;
  19.  
  20.     for (int i = start; i <= finish; i++) {
  21.         fr[a[i]]++;
  22.     }
  23.  
  24.     for (int i = 1; i <= nb; i++) {
  25.         if (fr[i] > b[i]) {
  26.             ans++;
  27.         } else if (fr[i] != b[i]) {
  28.             return INT_MAX;
  29.         }
  30.     }
  31.  
  32.     return ans;
  33. }
  34.  
  35. signed main() {
  36.     read();
  37.     int ans = INT_MAX;
  38.     for (int i = 1; i <= na; i++) {
  39.         for (int j = i; j <= na; j++) {
  40.             int currAns = solve(i, j);
  41.             ans = min(ans, currAns);
  42.         }
  43.     }
  44.     cout << ans << endl;//*/
  45.     return 0;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement