Advertisement
zhukov000

Example_n*m*m

Jan 29th, 2021
897
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.   for(int i=0; i<(int)buf.size(); ++i)
  13.     for(int j=i+1; j<(int)buf.size(); ++j)
  14.       if ( (buf[i] + buf[j]) % 2 == 0 )
  15.         mn_sum = min(mn_sum, buf[i] + buf[j]);
  16.   return mn_sum;
  17. }
  18.  
  19. int main()
  20. {
  21.   #ifdef AZHUKOV
  22.   freopen("input.txt", "r", stdin);
  23.   #endif // AZHUKOV
  24.  
  25.   vector<int> buf;
  26.  
  27.   for(int i=0; i<M; ++i)
  28.   {
  29.     int x;
  30.     cin >> x;
  31.     buf.push_back(x);
  32.   }
  33.  
  34.   int mn_sum = INF;
  35.   for(int i=M; i<1000; ++i)
  36.   {
  37.     int x;
  38.     cin >> x;
  39.     buf.push_back(x);
  40.     mn_sum = min(mn_sum, calc_mn_sum(buf));
  41.     buf.erase(buf.begin());
  42.   }
  43.   cout << mn_sum;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement