Advertisement
Mohammadjo123

c++/cmath

Jan 20th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cmath>
  4. #include <vector>
  5.  
  6. using namespace std;
  7. int main() {
  8.     ios_base::sync_with_stdio(false);
  9.     cin.tie(NULL);
  10.  
  11.     int n;
  12.     cin >> n;
  13.     vector<long long> a(n);
  14.  
  15.     for (int i = 0; i < n; ++i) {
  16.         cin >> a[i];
  17.     }
  18.  
  19.     sort(a.begin(), a.end());
  20.    
  21.     long long m = a.back();
  22.     long long l = 0;
  23.     long long h = 0;
  24.    
  25.     for (int i = 0; i < n; ++i) {
  26.         l += abs(a[i] - m);
  27.     }
  28.     int ans = 0;
  29.     while (h < l) {
  30.         a.pop_back();
  31.         long long new_m = a.back();
  32.        
  33.         long long diff = m - new_m;
  34.        
  35.         l -= diff * a.size();
  36.         h += m;
  37.         m = new_m;
  38.         ans++;
  39.     }
  40.    
  41.     cout << ans;
  42.  
  43.     return 0;
  44. }
  45. c++ vector
  46. c++ compiler
  47. c++ string
  48. c++ map
  49. c++ tutorial
  50. c++ array
  51. c++ programming
  52. c++ getline
  53. c++ set
  54. c++ assert
  55. c++ absolute value
  56. c++ auto
  57. c++ array length
  58. c++ abstract class
  59. c++ atoi
  60. c++ abs
  61. c++ array initialization
  62. c++ algorithm
  63. a c++ class is similar to a(n)
  64. a c++ program
  65. a c++ stream is
  66. a c++ code line ends with
  67. a c++ primer
  68. a c++ program for binary search
  69. a c++ program with class
  70. a c++ project
  71. a c++ program to reverse a number
  72. a c++ program example
  73. c++ basics
  74. c++ break
  75. c++ binary search
  76. c++ bitset
  77. c++ boost
  78. c++ book
  79. c++ boolean
  80. c++ bitwise operators
  81. c++ bubble sort
  82. b c++ backspace
  83. b c++ boolean
  84.  
  85. c++ 2 dimensional array
  86. c++ 2 dimensional vector
  87. c++ 2 decimal places
  88. c++ 2^n
  89. c++ 2 dimensional array initialization
  90. c++ 2's complement
  91. c++ 2 to the power of n
  92. c++ 2 dimensional array pointer
  93. c++ 9 redistributable
  94. c++ 9 for python
  95. c++ 9 download
  96. c++ 9 string to int
  97. netbeans 9 c++
  98. cloud9 c++
  99. 10^9 c++
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement