Advertisement
zhukov000

Example18_n*m

Jan 29th, 2021
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  4.  
  5. const int M = 5;
  6. const int INF = 1e9 + 7;
  7. using namespace std;
  8.  
  9. int calc_mn_sum(vector<int> &buf)
  10. {
  11.   int mn_sum = INF;
  12.   int mn[2] = {INF, INF};
  13.   for(int i=0; i<(int)buf.size(); ++i)
  14.   {
  15.     mn_sum = min(mn_sum, mn[buf[i]%2] + buf[i]);
  16.     mn[buf[i]%2] = min(mn[buf[i]%2], buf[i]);
  17.   }
  18.   return mn_sum;
  19. }
  20.  
  21. int main()
  22. {
  23.   #ifdef AZHUKOV
  24.   freopen("input.txt", "r", stdin);
  25.   #endif // AZHUKOV
  26.  
  27.   vector<int> buf;
  28.  
  29.   for(int i=0; i<M; ++i)
  30.   {
  31.     int x;
  32.     cin >> x;
  33.     buf.push_back(x);
  34.   }
  35.  
  36.   int mn_sum = INF;
  37.   for(int i=M; i<1000; ++i)
  38.   {
  39.     int x;
  40.     cin >> x;
  41.     buf.push_back(x);
  42.     mn_sum = min(mn_sum, calc_mn_sum(buf));
  43.     buf.erase(buf.begin());
  44.   }
  45.   cout << mn_sum;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement