T3000

Untitled

Mar 5th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef int64_t i64;
  5. using d6 = long double;
  6.  
  7. int main()
  8. {
  9.     i64 n, h;
  10.     cin >> n >> h;
  11.     map<i64, i64> ua, dw;
  12.     for (i64 i = 0; i < n; i++)
  13.     {
  14.         i64 tmp;
  15.         cin >> tmp;
  16.         if (i % 2 == 0)
  17.         {
  18.             ua[tmp] += 1;
  19.         }
  20.         else
  21.         {
  22.             dw[tmp] += 1;
  23.         }
  24.     }
  25.     i64 res = n;
  26.     i64 resc = 0;
  27.     i64 tu = n / 2;
  28.     i64 tw = 0;
  29.     for (i64 i = 1; i <= h; i++)
  30.     {
  31.         if (ua.count(i) > 0)
  32.         {
  33.             tu -= ua[i];
  34.         }
  35.         if (dw.count(h - i) > 0)
  36.         {
  37.             tw += dw[h - i];
  38.         }
  39.         if (res > tu + tw)
  40.         {
  41.             res = tu + tw;
  42.             resc = 1;
  43.         }
  44.         else
  45.         {
  46.             if (res == tu + tw)
  47.             {
  48.                 resc += 1;
  49.             }
  50.         }
  51.     }
  52.     cout << res << " " << resc << endl;
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment