fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define task ""
  4. using namespace std;
  5. static struct FastInput {
  6. static constexpr int BUF_SIZE = 1 << 20;
  7. char buf[BUF_SIZE];
  8. size_t chars_read = 0;
  9. size_t buf_pos = 0;
  10. FILE *in = stdin;
  11. char cur = 0;
  12.  
  13. inline char get_char() {
  14. if (buf_pos >= chars_read) {
  15. chars_read = fread(buf, 1, BUF_SIZE, in);
  16. buf_pos = 0;
  17. buf[0] = (chars_read == 0 ? -1 : buf[0]);
  18. }
  19. return cur = buf[buf_pos++];
  20. }
  21.  
  22. inline void tie(int) {}
  23.  
  24. inline explicit operator bool() {
  25. return cur != -1;
  26. }
  27.  
  28. inline static bool is_blank(char c) {
  29. return c <= ' ';
  30. }
  31.  
  32. inline bool skip_blanks() {
  33. while (is_blank(cur) && cur != -1) {
  34. get_char();
  35. }
  36. return cur != -1;
  37. }
  38.  
  39. inline FastInput& operator>>(char& c) {
  40. skip_blanks();
  41. c = cur;
  42. return *this;
  43. }
  44.  
  45. inline FastInput& operator>>(string& s) {
  46. if (skip_blanks()) {
  47. s.clear();
  48. do {
  49. s += cur;
  50. } while (!is_blank(get_char()));
  51. }
  52. return *this;
  53. }
  54.  
  55. template <typename T>
  56. inline FastInput& read_integer(T& n) {
  57. n = 0;
  58. if (skip_blanks()) {
  59. int sign = +1;
  60. if (cur == '-') {
  61. sign = -1;
  62. get_char();
  63. }
  64. do {
  65. n += n + (n << 3) + cur - '0';
  66. } while (!is_blank(get_char()));
  67. n *= sign;
  68. }
  69. return *this;
  70. }
  71.  
  72. template <typename T>
  73. inline typename enable_if<is_integral<T>::value, FastInput&>::type operator>>(T& n) {
  74. return read_integer(n);
  75. }
  76.  
  77. #if !defined(_WIN32) | defined(_WIN64)
  78. inline FastInput& operator>>(__int128& n) {
  79. return read_integer(n);
  80. }
  81. #endif
  82.  
  83. template <typename T>
  84. inline typename enable_if<is_floating_point<T>::value, FastInput&>::type operator>>(T& n) {
  85. n = 0;
  86. if (skip_blanks()) {
  87. string s;
  88. (*this) >> s;
  89. sscanf(s.c_str(), "%lf", &n);
  90. }
  91. return *this;
  92. }
  93. } fast_input;
  94. #define cin fast_input
  95. const ll N=1e6+11;
  96. ll a[N],n,k,s=0,ans=-1;
  97. bool check(ll mid){
  98. ll d=0;
  99. for(ll i=1;i<=n;i++){
  100. d+=a[i]/mid;
  101. if(d>=k){
  102. return true;
  103. }
  104. }
  105. return false;
  106. }
  107. void chatnp(ll l,ll r){
  108. while(l<=r){
  109. ll mid=(l+r)/2;
  110. if(check(mid)){
  111. ans=mid;
  112. l=mid+1;
  113. }
  114. else{
  115. r=mid-1;
  116. }
  117. }
  118. }
  119. void input(){
  120. cin>>n>>k;
  121. for(ll i=1;i<=n;i++){
  122. cin>>a[i];
  123. }
  124. }
  125. void output(){
  126. cout<<ans;
  127. }
  128. int main(){
  129. freopen("SOCOLA.INP","r",stdin);
  130. freopen("SOCOLA.OUT","w",stdout);
  131. input();
  132. chatnp(1,1e9);
  133. output();
  134. }
  135.  
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
Standard output is empty