fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<int> tab;
  5.  
  6. bool czy(int x,int n,int k)
  7. {
  8. vector<int> lis;
  9. vector<int> dp(k+3,0);
  10. for(int i = 0;i < n;++i)
  11. {
  12. if(tab[i] >= x)
  13. {
  14. lis.push_back(1);
  15. }
  16. else
  17. {
  18. lis.push_back(0);
  19. }
  20. }
  21. for(int i = n-1;i >= 0;i--)
  22. {
  23. int j = i%k;
  24. dp[j] = max(dp[j],dp[j+1] + lis[i]);
  25. }
  26. for(int i = 0;i < n;++i)
  27. {
  28. cout << dp[i] << ' ';
  29. }
  30. //cout << dp[k-1] << endl;
  31. if(dp[0] >= ((n%k)+1)/2) return true;
  32. return false;
  33. //cout << dp[k-1] << endl;
  34. }
  35.  
  36. int main()
  37. {
  38. int t;
  39. cin >> t;
  40. for(int q = 0;q < t;++q)
  41. {
  42. int n,k,x;
  43. cin >> n >> k;
  44. for(int i = 0;i < n;++i)
  45. {
  46. cin >> x;
  47. tab.push_back(x);
  48. }
  49. cout << czy(4,n,k) << endl;
  50. /*int l = 0,p=1000000003,mid;
  51. while(l < p)
  52. {
  53. mid = (l+p+1)/2;
  54. if(czy(mid,n,k))
  55. {
  56. l = mid;
  57. }
  58. else
  59. {
  60. p = mid-1;
  61. }
  62. }
  63. cout << l << endl;*/
  64. }
  65. }
  66.  
Success #stdin #stdout 0.01s 5284KB
stdin
5
4 3
3 9 9 2
5 3
3 2 5 6 4
7 1
5 9 2 6 5 4 6
8 2
7 1 2 6 8 3 4 5
4 5
3 4 5 6
stdout
2 2 1 0 1
2 2 1 0 0 1
1 0 0 0 0 0 33 1
2 1 0 0 0 0 33 0 1
2 2 1 0 1