fork download
  1. /*input
  2. 5 1
  3. 1 2 3 4 5
  4. */
  5. #include<bits/stdc++.h>
  6. using namespace std;
  7. const int N=1e5+10;
  8. #define int long long
  9. #define pii pair<int, int>
  10. #define f first
  11. #define s second
  12. inline pii mp(int a, int b)
  13. {
  14. pii temp;temp.f=a;temp.s=b;return temp;
  15. }
  16. int l, n, arr[N];
  17. bool p(int val)
  18. {
  19. int ct=1, cur=arr[1];
  20. if(cur<val) return false;
  21. for(int i=2;i<=n;i++)
  22. {
  23. cur&=arr[i];
  24. if(cur<val)
  25. {
  26. ct++;cur=arr[i];
  27. }
  28. }
  29. return (ct<=l);
  30. }
  31. signed main()
  32. {
  33. ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  34. freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
  35. cin>>n>>l;int low=0, high=1e9 + 10;
  36. for(int i=1;i<=n;i++)
  37. {
  38. cin>>arr[i];high=min(high, arr[i]);
  39. }
  40.  
  41. while(low<high)
  42. {
  43. int mid=(low+high+1)/2;
  44. if(p(mid))
  45. {
  46. low=mid;
  47. }
  48. else high=mid-1;
  49. }
  50. cout<<low;
  51. }
Runtime error #stdin #stdout #stderr 0s 16016KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::ios_base::failure[abi:cxx11]'
  what():  basic_filebuf::underflow error reading the file: iostream error