priyam2k

DSTROY

Jan 7th, 2020
85
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "bits/stdc++.h"
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. typedef long long ll;
  6. using namespace __gnu_pbds;
  7. using namespace std;
  8.  
  9. #define pb push_back
  10. //#define mp make_pair
  11. #define ff first
  12. #define ss second
  13. #define len(v) ((int)v.size())
  14. #define all(v) v.begin(), v.end()
  15. #define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  16. ll mod=998244353;
  17. void io(){
  18. ios_base::sync_with_stdio(false);
  19. cin.tie(NULL);
  20. cout.tie(NULL);
  21. #ifndef ONLINE_JUDGE
  22. freopen("input_6.txt","r",stdin);
  23. freopen("output_6.txt","w",stdout);
  24. #endif
  25. }
  26.  
  27. const int N = 1e6 + 5;
  28. long long a[N];
  29. ll summ;
  30. int main()
  31. {
  32. io();
  33. int n, k;
  34. cin >> n >> k;
  35. for(int i = 0; i<n; i++) {
  36. cin >> a[i];
  37. summ+=a[i];
  38. }
  39.  
  40. long long l = 0, r = 1e18, m;
  41. while( l+1 < r) {
  42.  
  43. long long sum = 0;
  44. m = l + r;
  45. m = m / 2;
  46. for(int i = 0; i < n; i++) {
  47. if(a[i] > m)
  48. sum += m;
  49. else
  50. sum += a[i];
  51. }
  52. if((sum / m) >= k)
  53. l = m;
  54. else r = m;
  55. }
  56. cout << l;
  57. }
RAW Paste Data