egogoboy

"Свадьба"

Jun 16th, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <stdio.h>
  6. using namespace std;
  7.  
  8. bool comp(int& x1, int& x2)
  9. {
  10.     return x1 < x2;    
  11. }
  12.  
  13. int main() {
  14.  
  15.     std::ifstream fin("input.txt");
  16.     std::ofstream fout("output.txt");
  17.  
  18.     int n;
  19.     fin >> n;
  20.     vector<int> m(n);
  21.  
  22.     for (int i = 0; i < n; i++) {
  23.         fin >> m[i];
  24.     }
  25.  
  26.     sort(m.begin(), m.end(), comp);
  27.  
  28.     double g;
  29.     fin >> g;
  30.    
  31.     for (int i = 0; i < n; i++) {
  32.         if (g < m[i]) {
  33.             g += m[i];
  34.             g /= 2;
  35.         }
  36.     }
  37.  
  38.     fout << fixed;
  39.     fout.precision(6);
  40.     fout << g;
  41.  
  42.     return 0;
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment