fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. long long n,k;
  6. long long t;
  7. scanf("%lld",&t);
  8. while(t--)
  9. {
  10. scanf("%lld %lld",&n,&k);
  11. long long ans = 1;
  12. long long curr = k;
  13. long long x;
  14. while(n--)
  15. {
  16. scanf("%lld",&x);
  17. if(x>curr)
  18. {
  19. x = x - curr;
  20. long long req = x/k;
  21. ans+=req;
  22. if(x%k!=0)
  23. {
  24. ans++;
  25. }
  26. curr = k - (x%k) - 1;
  27. }
  28. else
  29. {
  30. if(x==curr)
  31. {
  32. curr=0;
  33. }
  34. else
  35. {
  36. curr = curr - x -1;
  37. }
  38. }
  39. }
  40. printf("%lld\n",ans);
  41. }
  42. }
Time limit exceeded #stdin #stdout 5s 2684KB
stdin
Standard input is empty
stdout
Standard output is empty